MCPcopy Index your code
hub / github.com/supabase/auth / enrollWebAuthnFactor

Method enrollWebAuthnFactor

internal/api/mfa.go:198–230  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, params *EnrollFactorParams)

Source from the content-addressed store, hash-verified

196}
197
198func (a *API) enrollWebAuthnFactor(w http.ResponseWriter, r *http.Request, params *EnrollFactorParams) error {
199 ctx := r.Context()
200 user := getUser(ctx)
201 config := a.config
202 session := getSession(ctx)
203 db := a.db.WithContext(ctx)
204
205 if err := validateFactors(db, user, params.FriendlyName, a.config, session); err != nil {
206 return err
207 }
208
209 factor := models.NewWebAuthnFactor(user, params.FriendlyName)
210 err := db.Transaction(func(tx *storage.Connection) error {
211 if terr := tx.Create(factor); terr != nil {
212 return terr
213 }
214 if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.EnrollFactorAction, utilities.GetIPAddress(r), map[string]interface{}{
215 "factor_id": factor.ID,
216 "factor_type": factor.FactorType,
217 }); terr != nil {
218 return terr
219 }
220 return nil
221 })
222 if err != nil {
223 return err
224 }
225 return sendJSON(w, http.StatusOK, &EnrollFactorResponse{
226 ID: factor.ID,
227 Type: models.WebAuthn,
228 FriendlyName: factor.FriendlyName,
229 })
230}
231
232func (a *API) enrollTOTPFactor(w http.ResponseWriter, r *http.Request, params *EnrollFactorParams) error {
233 ctx := r.Context()

Callers 1

EnrollFactorMethod · 0.95

Calls 9

NewWebAuthnFactorFunction · 0.92
NewAuditLogEntryFunction · 0.92
GetIPAddressFunction · 0.92
getUserFunction · 0.85
getSessionFunction · 0.85
validateFactorsFunction · 0.85
sendJSONFunction · 0.85
WithContextMethod · 0.80
TransactionMethod · 0.80

Tested by

no test coverage detected