Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update mfa admin methods #1774

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions internal/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,9 @@ func (a *API) adminUserUpdateFactor(w http.ResponseWriter, r *http.Request) erro
return terr
}
}
if params.FactorType != "" {
if params.FactorType != models.TOTP {
return badRequestError(ErrorCodeValidationFailed, "Factor Type not valid")
J0 marked this conversation as resolved.
Show resolved Hide resolved
}
if terr := factor.UpdateFactorType(tx, params.FactorType); terr != nil {

if params.Phone != "" && factor.IsPhoneFactor() {
if terr := factor.UpdatePhone(tx, params.Phone); terr != nil {
return terr
}
}
Expand Down
12 changes: 6 additions & 6 deletions internal/models/factor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

const TOTP = "totp"
const Phone = "phone"
const WebAuthn = "webauthn"
J0 marked this conversation as resolved.
Show resolved Hide resolved

type AuthenticationMethod int

Expand Down Expand Up @@ -245,18 +246,17 @@
return tx.UpdateOnly(f, "friendly_name", "updated_at")
}

func (f *Factor) UpdatePhone(tx *storage.Connection, phone string) error {
f.Phone = phone

Check failure on line 250 in internal/models/factor.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

cannot use phone (variable of type string) as storage.NullString value in assignment
return tx.UpdateOnly(f, "phone", "updated_at")
}

// UpdateStatus modifies the factor status
func (f *Factor) UpdateStatus(tx *storage.Connection, state FactorState) error {
f.Status = state.String()
return tx.UpdateOnly(f, "status", "updated_at")
}

// UpdateFactorType modifies the factor type
func (f *Factor) UpdateFactorType(tx *storage.Connection, factorType string) error {
f.FactorType = factorType
return tx.UpdateOnly(f, "factor_type", "updated_at")
}

func (f *Factor) DowngradeSessionsToAAL1(tx *storage.Connection) error {
sessions, err := FindSessionsByFactorID(tx, f.ID)
if err != nil {
Expand Down
Loading