(w http.ResponseWriter, r *http.Request)
| 304 | } |
| 305 | |
| 306 | func (a *API) EnrollFactor(w http.ResponseWriter, r *http.Request) error { |
| 307 | ctx := r.Context() |
| 308 | user := getUser(ctx) |
| 309 | session := getSession(ctx) |
| 310 | config := a.config |
| 311 | |
| 312 | if session == nil || user == nil { |
| 313 | return apierrors.NewInternalServerError("A valid session and a registered user are required to enroll a factor") |
| 314 | } |
| 315 | params := &EnrollFactorParams{} |
| 316 | if err := retrieveRequestParams(r, params); err != nil { |
| 317 | return err |
| 318 | } |
| 319 | |
| 320 | switch params.FactorType { |
| 321 | case models.Phone: |
| 322 | if !config.MFA.Phone.EnrollEnabled { |
| 323 | return apierrors.NewUnprocessableEntityError(apierrors.ErrorCodeMFAPhoneEnrollDisabled, "MFA enroll is disabled for Phone") |
| 324 | } |
| 325 | return a.enrollPhoneFactor(w, r, params) |
| 326 | case models.TOTP: |
| 327 | if !config.MFA.TOTP.EnrollEnabled { |
| 328 | return apierrors.NewUnprocessableEntityError(apierrors.ErrorCodeMFATOTPEnrollDisabled, "MFA enroll is disabled for TOTP") |
| 329 | } |
| 330 | return a.enrollTOTPFactor(w, r, params) |
| 331 | case models.WebAuthn: |
| 332 | if !config.MFA.WebAuthn.EnrollEnabled { |
| 333 | return apierrors.NewUnprocessableEntityError(apierrors.ErrorCodeMFAWebAuthnEnrollDisabled, "MFA enroll is disabled for WebAuthn") |
| 334 | } |
| 335 | return a.enrollWebAuthnFactor(w, r, params) |
| 336 | default: |
| 337 | return apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "factor_type needs to be totp, phone, or webauthn") |
| 338 | } |
| 339 | |
| 340 | } |
| 341 | |
| 342 | func (a *API) challengePhoneFactor(w http.ResponseWriter, r *http.Request) error { |
| 343 | ctx := r.Context() |
nothing calls this directly
no test coverage detected