Class AuthenticationController

java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.controller.AuthenticationController

@RestController @CrossOrigin @RequestMapping("/auth") public class AuthenticationController extends Object
Controller used for registering and logging in a user and returning access and refresh tokens
Since:
17.4.24
Version:
1.0
Author:
Lars N, Harry X.
  • Constructor Details

    • AuthenticationController

      public AuthenticationController()
  • Method Details

    • register

      @PostMapping("/register") public org.springframework.http.ResponseEntity<LoginRegisterResponse> register(@RequestBody RegisterRequest registerRequest) throws BadInputException, ObjectNotValidException, UserAlreadyExistsException
      Registers a new user with a given username, password, email, first name and last name
      Parameters:
      registerRequest - Wrapper for user info
      Returns:
      ResponseEntity containing access and refresh tokens upon successful registration
      Throws:
      BadInputException - If the username, first name last name or email is invalid or the password is too weak
      UserAlreadyExistsException - If the username is already taken
      ObjectNotValidException
    • login

      @PostMapping("/login") public org.springframework.http.ResponseEntity<LoginRegisterResponse> login(@RequestBody AuthenticationRequest authRequest) throws BadInputException, ObjectNotValidException
      Log in an existing user with username and password
      Parameters:
      authRequest - Wrapper for username and password
      Returns:
      ResponseEntity containing access and refresh tokens upon successful login
      Throws:
      BadInputException - If the username or password is incorrect
      ObjectNotValidException
    • renewAccessToken

      @GetMapping("/renewToken") public org.springframework.http.ResponseEntity<AccessTokenResponse> renewAccessToken(@RequestHeader("Authorization") String bearerToken)
      Refreshes the access token using a valid refresh token.
      Parameters:
      bearerToken - Bearer token in authorization header
      Returns:
      ResponseEntity containing a new access token
    • bioAuthRegistration

      @PostMapping("/bioRegistration") public org.springframework.http.ResponseEntity<String> bioAuthRegistration(@AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws UserNotFoundException, com.fasterxml.jackson.core.JsonProcessingException
      Initiates the biometric authentication registration process for a user.
      Parameters:
      userDetails - The details of the authenticated user
      Returns:
      ResponseEntity containing the options for biometric authentication registration
      Throws:
      UserNotFoundException - If the user is not found
      com.fasterxml.jackson.core.JsonProcessingException - If an error occurs during JSON processing
    • finishRegistration

      @PostMapping("/finishBioRegistration") public org.springframework.http.ResponseEntity<Void> finishRegistration(@RequestBody BioAuthRequest credential, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws com.yubico.webauthn.exception.RegistrationFailedException, IOException
      Completes the passkey authentication registration process for a user.
      Parameters:
      credential - The biometric authentication credential
      userDetails - The details of the authenticated user
      Returns:
      ResponseEntity indicating the success of the registration process
      Throws:
      com.yubico.webauthn.exception.RegistrationFailedException - If the registration fails
      IOException - If an I/O error occurs
    • startBioLogin

      @PostMapping("/bioLogin/{username}") public org.springframework.http.ResponseEntity<String> startBioLogin(@PathVariable String username) throws com.fasterxml.jackson.core.JsonProcessingException
      Initiates the biometric authentication login process for a user.
      Parameters:
      username - The username of the user
      Returns:
      ResponseEntity containing the options for biometric authentication login
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - If an error occurs during JSON processing
    • finishLogin

      @PostMapping("/finishBioLogin/{username}") public org.springframework.http.ResponseEntity<LoginRegisterResponse> finishLogin(@PathVariable String username, @RequestBody BioAuthRequest credential) throws IOException, com.yubico.webauthn.exception.AssertionFailedException
      Completes the biometric authentication login process for a user.
      Parameters:
      username - The username of the user
      credential - The biometric authentication credential
      Returns:
      ResponseEntity containing access and refresh tokens upon successful login
      Throws:
      IOException - If an I/O error occurs
      com.yubico.webauthn.exception.AssertionFailedException - If the assertion fails