Class AuthController

java.lang.Object
com.example.blogs.app.api.auth.controller.AuthController

@RestController @RequestMapping("/auth") public class AuthController extends Object
REST controller for user authentication, registration, and token management. Provides endpoints for user registration, login, token refresh, logout, and retrieving authenticated user information.
  • Constructor Details

    • AuthController

      public AuthController()
  • Method Details

    • register

      @PostMapping("/register") public ResponseEntity<TokenPair> register(@NotNull @Valid @RequestBody @NotNull @Valid RegisterRequest registerRequest)
      Registers a new user and returns authentication tokens.
      Parameters:
      registerRequest - the registration details including username, email, and password
      Returns:
      HTTP 201 with access and refresh tokens
    • login

      @PostMapping("/login") public ResponseEntity<TokenPair> login(@NotNull @Valid @RequestBody @NotNull @Valid LoginRequest loginRequest)
      Authenticates a user and returns authentication tokens.
      Parameters:
      loginRequest - the login credentials including username/email and password
      Returns:
      HTTP 200 with access and refresh tokens
    • me

      @GetMapping("/me") public ResponseEntity<UserPrincipal> me(@AuthenticationPrincipal UserPrincipal user)
      Returns the authenticated user's principal information.
      Parameters:
      user - the authenticated user principal from the JWT token
      Returns:
      HTTP 200 with user principal details
    • refreshToken

      @PostMapping("/refresh") public ResponseEntity<AccessTokenResponse> refreshToken(@NotNull @Valid @RequestBody @NotNull @Valid RefreshTokenRequest tokenRequest)
      Refreshes the access token using a valid refresh token.
      Parameters:
      tokenRequest - the refresh token request containing the refresh token
      Returns:
      HTTP 200 with a new access token
    • logout

      @PostMapping("/logout") public ResponseEntity<Void> logout(@NotNull @Valid @RequestBody @NotNull @Valid LogoutRequest logoutRequest)
      Revokes a refresh token to log out the user.
      Parameters:
      logoutRequest - the logout request containing the refresh token to revoke
      Returns:
      HTTP 204 No Content on successful logout