(w http.ResponseWriter, r *http.Request)
| 987 | } |
| 988 | |
| 989 | func (a *API) VerifyFactor(w http.ResponseWriter, r *http.Request) error { |
| 990 | ctx := r.Context() |
| 991 | factor := getFactor(ctx) |
| 992 | config := a.config |
| 993 | |
| 994 | params := &VerifyFactorParams{} |
| 995 | if err := retrieveRequestParams(r, params); err != nil { |
| 996 | return err |
| 997 | } |
| 998 | if params.Code == "" && factor.FactorType != models.WebAuthn { |
| 999 | return apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "Code needs to be non-empty") |
| 1000 | } |
| 1001 | |
| 1002 | switch factor.FactorType { |
| 1003 | case models.Phone: |
| 1004 | if !config.MFA.Phone.VerifyEnabled { |
| 1005 | return apierrors.NewUnprocessableEntityError(apierrors.ErrorCodeMFAPhoneVerifyDisabled, "MFA verification is disabled for Phone") |
| 1006 | } |
| 1007 | |
| 1008 | return a.verifyPhoneFactor(w, r, params) |
| 1009 | case models.TOTP: |
| 1010 | if !config.MFA.TOTP.VerifyEnabled { |
| 1011 | return apierrors.NewUnprocessableEntityError(apierrors.ErrorCodeMFATOTPVerifyDisabled, "MFA verification is disabled for TOTP") |
| 1012 | } |
| 1013 | return a.verifyTOTPFactor(w, r, params) |
| 1014 | case models.WebAuthn: |
| 1015 | if !config.MFA.WebAuthn.VerifyEnabled { |
| 1016 | return apierrors.NewUnprocessableEntityError(apierrors.ErrorCodeMFAWebAuthnEnrollDisabled, "MFA verification is disabled for WebAuthn") |
| 1017 | } |
| 1018 | return a.verifyWebAuthnFactor(w, r, params) |
| 1019 | default: |
| 1020 | return apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "factor_type needs to be totp, phone, or webauthn") |
| 1021 | } |
| 1022 | |
| 1023 | } |
| 1024 | |
| 1025 | func (a *API) UnenrollFactor(w http.ResponseWriter, r *http.Request) error { |
| 1026 | var err error |
nothing calls this directly
no test coverage detected