(w http.ResponseWriter, r *http.Request)
| 426 | } |
| 427 | |
| 428 | func (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 | |
| 461 | func (a *API) challengeWebAuthnFactor(w http.ResponseWriter, r *http.Request) error { |
| 462 | ctx := r.Context() |
no test coverage detected