Package org.localify.auth
Class ApiAuthController
java.lang.Object
org.localify.auth.ApiAuthController
@RestController
@RequestMapping("/v1/auth")
@PreAuthorize("permitAll()")
@ConditionalOnWebApplication
public class ApiAuthController
extends Object
Controller for handling authentication-related API requests.
-
Constructor Summary
ConstructorsConstructorDescriptionApiAuthController(UserService userService, AppleLoginService appleLoginService, JwtService jwtService, GoogleLoginService googleLoginApi, SpotifyLoginService spotifyLoginApi, EmailLoginService emailLoginService, LoginService loginService, AppleMusicService appleMusicService) Constructs a new ApiAuthController. -
Method Summary
Modifier and TypeMethodDescriptionappleMusicLoginAttempt(@Valid AppleMusicLoginAttempt loginAttempt) Initiates an Apple Music login attempt.org.springframework.http.ResponseEntity<Void>appleMusicSendToken(@Valid AppleMusicTokenRequest loginAttempt) Sends the Apple Music user token to the server.authenticateUser(@Valid AuthTokenContainer body) Handle an initial Google token.authenticateUserAppleToken(@Valid AppleLoginRequest request) Authenticates a user with an Apple token.voidemailUnsubscribe(UUID userId, @Valid EmailUnsubscribeRequest request) Unsubscribes a user from emails.Logs in a guest user.loginByEmailToken(@Valid UserEmailTokenLoginRequest request) Logs in a user with an email token.sendEmailToken(@Valid UserEmailTokenRequest request) Sends a login token to the user's email.org.springframework.http.ResponseEntity<Void>spotifyCallback(String code, String stateJwt) Handles the callback from Spotify after a successful login.org.springframework.http.ResponseEntity<Void>spotifyLogin(@Valid UserOAuthRedirectParams params) Redirects the user to the Spotify login page.tokenRefresh(@Valid AuthTokenContainer body) Refreshes an authentication token.userCallbackToken(@Valid UserCallbackTokenPayload payload) Handles the callback from the identity provider with a user token.
-
Constructor Details
-
ApiAuthController
public ApiAuthController(UserService userService, AppleLoginService appleLoginService, JwtService jwtService, GoogleLoginService googleLoginApi, SpotifyLoginService spotifyLoginApi, EmailLoginService emailLoginService, LoginService loginService, AppleMusicService appleMusicService) Constructs a new ApiAuthController.- Parameters:
userService- The user service.appleLoginService- The Apple login service.jwtService- The JWT service.googleLoginApi- The Google login service.spotifyLoginApi- The Spotify login service.emailLoginService- The email login service.loginService- The generic login service.appleMusicService- The Apple Music service.
-
-
Method Details
-
guestLogin
Logs in a guest user.- Returns:
- The authentication credentials for the guest user.
-
spotifyLogin
@GetMapping("spotify/login") @ResponseBody public org.springframework.http.ResponseEntity<Void> spotifyLogin(@Valid @Valid UserOAuthRedirectParams params) Redirects the user to the Spotify login page.- Parameters:
params- The redirect parameters.- Returns:
- A redirect response to the Spotify login page.
-
userCallbackToken
@PostMapping("token") @ResponseBody @ResponseStatus(CREATED) public AuthCredentials userCallbackToken(@RequestBody @Valid @Valid UserCallbackTokenPayload payload) Handles the callback from the identity provider with a user token.- Parameters:
payload- The payload containing the callback token.- Returns:
- The authentication credentials for the user.
-
appleMusicLoginAttempt
@PostMapping("apple-music/attempt") @ResponseBody public AppleMusicRequestAttempt appleMusicLoginAttempt(@RequestBody @Valid @Valid AppleMusicLoginAttempt loginAttempt) Initiates an Apple Music login attempt.- Parameters:
loginAttempt- The login attempt details.- Returns:
- The request attempt data.
-
appleMusicSendToken
@PostMapping("apple-music/token") @ResponseBody public org.springframework.http.ResponseEntity<Void> appleMusicSendToken(@RequestBody @Valid @Valid AppleMusicTokenRequest loginAttempt) throws URISyntaxException Sends the Apple Music user token to the server.- Parameters:
loginAttempt- The token request details.- Returns:
- A redirect response.
- Throws:
URISyntaxException- if the redirect URL is invalid.
-
spotifyCallback
@GetMapping("spotify/callback") public org.springframework.http.ResponseEntity<Void> spotifyCallback(@RequestParam String code, @RequestParam(name="state") String stateJwt) throws URISyntaxException Handles the callback from Spotify after a successful login.- Parameters:
code- The authorization code from Spotify.stateJwt- The state JWT.- Returns:
- A redirect response to the client application.
- Throws:
URISyntaxException- if the redirect URI is invalid.
-
authenticateUser
@PostMapping(value="google/token", produces="application/json") @ResponseStatus(CREATED) @ResponseBody public AuthCredentials authenticateUser(@RequestBody @Valid @Valid AuthTokenContainer body) Handle an initial Google token.- Parameters:
body- the initial google token- Returns:
- ResponseEntity with the user's auth and refresh tokens.
-
tokenRefresh
@PostMapping(value="refresh", produces="application/json") @ResponseStatus(CREATED) @ResponseBody public AuthCredentials tokenRefresh(@RequestBody @Valid @Valid AuthTokenContainer body) Refreshes an authentication token.- Parameters:
body- The container with the refresh token.- Returns:
- New authentication credentials.
-
authenticateUserAppleToken
@PostMapping(value="apple/token", produces="application/json") @ResponseBody public AuthCredentials authenticateUserAppleToken(@RequestBody @Valid @Valid AppleLoginRequest request) Authenticates a user with an Apple token.- Parameters:
request- The Apple login request.- Returns:
- The authentication credentials.
-
sendEmailToken
@PostMapping("email/send-token") @ResponseStatus(CREATED) public UserEmailTokenLoginResponse sendEmailToken(@RequestBody @Valid @Valid UserEmailTokenRequest request) Sends a login token to the user's email.- Parameters:
request- The request containing the user's email.- Returns:
- A response containing the nonce for the login attempt.
-
loginByEmailToken
@PostMapping("email/login") public AuthCredentials loginByEmailToken(@RequestBody @Valid @Valid UserEmailTokenLoginRequest request) Logs in a user with an email token.- Parameters:
request- The request containing the nonce and code.- Returns:
- The authentication credentials.
-
emailUnsubscribe
@PostMapping("email/unsubscribe/{userId}") public void emailUnsubscribe(@PathVariable UUID userId, @RequestBody @Valid @Valid EmailUnsubscribeRequest request) Unsubscribes a user from emails.- Parameters:
userId- The ID of the user to unsubscribe.request- The request containing the unsubscribe token.
-