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

Method challengeTOTPFactor

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

Source from the content-addressed store, hash-verified

426}
427
428func (a *API) challengeTOTPFactor(w http.ResponseWriter, r *http.Request) error {
429 ctx := r.Context()
430 config := a.config
431 db := a.db.WithContext(ctx)
432
433 user := getUser(ctx)
434 factor := getFactor(ctx)
435 ipAddress := utilities.GetIPAddress(r)
436
437 challenge := factor.CreateChallenge(ipAddress)
438
439 if err := db.Transaction(func(tx *storage.Connection) error {
440 if terr := factor.WriteChallengeToDatabase(tx, challenge); terr != nil {
441 return terr
442 }
443 if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.CreateChallengeAction, utilities.GetIPAddress(r), map[string]interface{}{
444 "factor_id": factor.ID,
445 "factor_status": factor.Status,
446 }); terr != nil {
447 return terr
448 }
449 return nil
450 }); err != nil {
451 return err
452 }
453
454 return sendJSON(w, http.StatusOK, &ChallengeFactorResponse{
455 ID: challenge.ID,
456 Type: factor.FactorType,
457 ExpiresAt: challenge.GetExpiryTime(config.MFA.ChallengeExpiryDuration).Unix(),
458 })
459}
460
461func (a *API) challengeWebAuthnFactor(w http.ResponseWriter, r *http.Request) error {
462 ctx := r.Context()

Callers 1

ChallengeFactorMethod · 0.95

Calls 10

GetIPAddressFunction · 0.92
NewAuditLogEntryFunction · 0.92
getUserFunction · 0.85
getFactorFunction · 0.85
sendJSONFunction · 0.85
WithContextMethod · 0.80
CreateChallengeMethod · 0.80
TransactionMethod · 0.80
GetExpiryTimeMethod · 0.80

Tested by

no test coverage detected