Class AuthServiceImpl

java.lang.Object
com.example.blogs.app.api.auth.service.AuthServiceImpl
All Implemented Interfaces:
AuthService

@Service public class AuthServiceImpl extends Object implements AuthService
Orchestrates user authentication operations by coordinating password hashing, user validation, and token generation.
  • Constructor Details

    • AuthServiceImpl

      public AuthServiceImpl()
  • Method Details

    • register

      public TokenPair register(RegisterRequest registerRequest)
      Description copied from interface: AuthService
      Registers a new user and returns JWT tokens for immediate authentication.
      Specified by:
      register in interface AuthService
      Parameters:
      registerRequest - user registration details
      Returns:
      access and refresh token pair
    • login

      public TokenPair login(LoginRequest loginRequest)
      Description copied from interface: AuthService
      Authenticates a user and generates JWT tokens.
      Specified by:
      login in interface AuthService
      Parameters:
      loginRequest - user login credentials
      Returns:
      access and refresh token pair
    • refreshAccessToken

      public AccessTokenResponse refreshAccessToken(RefreshTokenRequest tokenRequest)
      Refreshes an access token by validating the refresh token and generating a new access token. Verifies that the token is valid, not expired, and is of type "refresh".
      Specified by:
      refreshAccessToken in interface AuthService
      Parameters:
      tokenRequest - request containing the refresh token
      Returns:
      new access token with user claims and updated expiration
      Throws:
      UnauthorizedException - if refresh token is invalid, expired, or not a refresh token type
    • logout

      public RevokedTokenEntity logout(LogoutRequest logoutRequest)
      Description copied from interface: AuthService
      Revokes a refresh token and invalidates all associated sessions.
      Specified by:
      logout in interface AuthService
      Parameters:
      logoutRequest - request containing the refresh token to revoke
      Returns:
      persisted revoked token entity