MCPcopy Create free account
hub / github.com/supabase/auth / EnrollFactor

Method EnrollFactor

internal/api/mfa.go:306–340  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

304}
305
306func (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
342func (a *API) challengePhoneFactor(w http.ResponseWriter, r *http.Request) error {
343 ctx := r.Context()

Callers

nothing calls this directly

Calls 9

enrollPhoneFactorMethod · 0.95
enrollTOTPFactorMethod · 0.95
enrollWebAuthnFactorMethod · 0.95
NewInternalServerErrorFunction · 0.92
NewBadRequestErrorFunction · 0.92
getUserFunction · 0.85
getSessionFunction · 0.85
retrieveRequestParamsFunction · 0.85

Tested by

no test coverage detected