java.lang.Object
com.irurueta.authserver.authorization.api.web.totp.TotpController
All Implemented Interfaces:
TotpApi

@RestController public class TotpController extends Object implements TotpApi
Enrols, confirms and disables the authenticator app of the authenticated account. The paths, status codes and bodies are those of the contract apis/auth-server/rest-server/auth-server-api-v1.yaml, through the generated TotpApi; failures are answered by MfaExceptionHandler. Answers that carry a secret are never cached. Disabling the app needs a recent multi-factor sign-in (StepUpGuard).
  • Field Details

    • currentAccountResolver

      private final CurrentAccountResolver currentAccountResolver
      Resolves the account of the request.
    • enrollTotpUseCase

      private final EnrollTotpUseCase enrollTotpUseCase
      Starts an enrolment.
    • confirmTotpUseCase

      private final ConfirmTotpUseCase confirmTotpUseCase
      Confirms an enrolment.
    • disableTotpUseCase

      private final DisableTotpUseCase disableTotpUseCase
      Disables the authenticator app.
    • stepUpGuard

      private final StepUpGuard stepUpGuard
      Requires a recent multi-factor sign-in before the second factor is removed.
    • qrCodeRenderer

      private final QrCodeRenderer qrCodeRenderer
      Renders the enrolment URI as a QR code.
    • totpDtoMapper

      private final TotpDtoMapper totpDtoMapper
      Maps the results onto the contract's DTOs.
  • Constructor Details

    • TotpController

      public TotpController()
  • Method Details

    • enrollTotp

      public org.springframework.http.ResponseEntity<TotpEnrollmentResponse> enrollTotp()
      Starts the enrolment of an authenticator app.
      Specified by:
      enrollTotp in interface TotpApi
      Returns:
      200 OK with the otpauth URI and its QR code.
    • confirmTotp

      public org.springframework.http.ResponseEntity<RecoveryCodesResponse> confirmTotp(ConfirmTotpRequest request)
      Confirms the enrolment with a code from the authenticator app.
      Specified by:
      confirmTotp in interface TotpApi
      Parameters:
      request - the code.
      Returns:
      200 OK with the recovery codes, shown only once.
    • disableTotp

      public org.springframework.http.ResponseEntity<Void> disableTotp()
      Disables the authenticator app, removes the recovery codes and revokes the trusted devices.
      Specified by:
      disableTotp in interface TotpApi
      Returns:
      204 No Content.
      Throws:
      InsufficientUserAuthenticationException - if the token does not show a recent multi-factor sign-in.
    • noStore

      private static <T> org.springframework.http.ResponseEntity<T> noStore(T body)
      Answers a body that carries a secret, which must not be cached.
      Type Parameters:
      T - type of the body.
      Parameters:
      body - the body.
      Returns:
      200 OK with Cache-Control: no-store.