Class JwtServiceImpl

java.lang.Object
org.localify.auth.JwtServiceImpl
All Implemented Interfaces:
JwtService

public class JwtServiceImpl extends Object implements JwtService
Implementation of the JwtService interface.
  • Constructor Details

    • JwtServiceImpl

      public JwtServiceImpl(RefreshTokenRepository refreshTokenRepository, io.jsonwebtoken.JwtParser jwtParser, Key key, LocalifyProperties properties, jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.persistence.EntityManager entityManager)
      Constructs a new JwtServiceImpl.
      Parameters:
      refreshTokenRepository - The repository for refresh tokens.
      jwtParser - The JWT parser.
      key - The signing key.
      properties - The application properties.
      servletRequest - The HTTP servlet request.
      entityManager - The entity manager.
  • Method Details

    • getClaims

      public io.jsonwebtoken.Claims getClaims(String token)
      See JwtParser.parseClaimsJws(String) for more detailed exception information.
      Specified by:
      getClaims in interface JwtService
      Parameters:
      token - the jwt token
      Returns:
      the Claims. Never null.
      Throws:
      io.jsonwebtoken.JwtException - if the token is invalid in some way (see link above)
      IllegalArgumentException - if the token is null/empty/whitespace.
    • doUserLogin

      public AuthCredentials doUserLogin(User user)
      Description copied from interface: JwtService
      Logs a user in. Generates new authentication and refresh credentials.
      Specified by:
      doUserLogin in interface JwtService
      Parameters:
      user - the user to generate credentials for.
      Returns:
      a DTO containing the auth and refresh token.
    • doRefreshToken

      public AuthCredentials doRefreshToken(String token)
      Description copied from interface: JwtService
      Refreshes a token, invalidating the refresh token.
      Specified by:
      doRefreshToken in interface JwtService
      Parameters:
      token - the refresh token
      Returns:
      newly generated auth and refresh token
    • generateAuthStateJwt

      public String generateAuthStateJwt(UserOAuthRedirectParams params)
      Specified by:
      generateAuthStateJwt in interface JwtService
    • decodeAuthStateJwt

      public UserOAuthRedirectParams decodeAuthStateJwt(String jwt)
      Specified by:
      decodeAuthStateJwt in interface JwtService
    • getKeyForToken

      public static Key getKeyForToken(String token)
      Gets the key for a given token.
      Parameters:
      token - The token string.
      Returns:
      The key.