Search in sources :

Example 1 with UserRefreshToken

use of com.ncedu.fooddelivery.api.v1.entities.UserRefreshToken in project 2021-msk-food-delivery by netcracker-edu.

the class UserRefreshTokenServiceImpl method createRefreshToken.

@Override
public String createRefreshToken(User owner, String userAgent) {
    UserRefreshToken urt = new UserRefreshToken();
    Timestamp createDate = Timestamp.valueOf(LocalDateTime.now());
    urt.setCreateDate(createDate);
    urt.setOwner(owner);
    urt.setUserAgent(userAgent);
    urt = userRefreshTokenRepo.save(urt);
    return urt.getId().toString();
}
Also used : UserRefreshToken(com.ncedu.fooddelivery.api.v1.entities.UserRefreshToken) Timestamp(java.sql.Timestamp)

Example 2 with UserRefreshToken

use of com.ncedu.fooddelivery.api.v1.entities.UserRefreshToken in project 2021-msk-food-delivery by netcracker-edu.

the class AuthServiceImpl method refresh.

@Override
public JwtResponseDTO refresh(RefreshTokenDTO refreshTokenDTO, String authHeader) {
    UUID refreshToken = UUID.fromString(refreshTokenDTO.getRefreshToken());
    UserRefreshToken urt = userRefreshTokenService.getTokenById(refreshToken);
    // change lastSignin on owner of token
    userService.setLastSigninFromNow(urt.getOwner());
    final String accessToken = jwtUtil.createToken(urt.getOwner());
    return new JwtResponseDTO(accessToken, refreshToken.toString(), createUserDTO(urt.getOwner()));
}
Also used : UUID(java.util.UUID) JwtResponseDTO(com.ncedu.fooddelivery.api.v1.dto.jwt.JwtResponseDTO)

Aggregations

JwtResponseDTO (com.ncedu.fooddelivery.api.v1.dto.jwt.JwtResponseDTO)1 UserRefreshToken (com.ncedu.fooddelivery.api.v1.entities.UserRefreshToken)1 Timestamp (java.sql.Timestamp)1 UUID (java.util.UUID)1