(w http.ResponseWriter, r *http.Request, params *EnrollFactorParams)
| 196 | } |
| 197 | |
| 198 | func (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 | |
| 232 | func (a *API) enrollTOTPFactor(w http.ResponseWriter, r *http.Request, params *EnrollFactorParams) error { |
| 233 | ctx := r.Context() |
no test coverage detected