Skip to content

Commit

Permalink
fix: always use custom user handle if available
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddyDevelop committed Dec 5, 2024
1 parent 77b0ad8 commit 58a0397
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions backend/flow_api/services/webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,10 @@ func (s *webauthnService) VerifyAssertionResponse(p VerifyAssertionResponseParam
}

var userID uuid.UUID
// Only get the userID when it is a mfa login. For passkeys the userID will be found out in GetWebAuthnUser.
// Otherwise, a custom user handle could not be an uuid.
if p.IsMFA {
userID = sessionDataModel.UserId
} else {
// When the UserHandle is not an uuid it is assumed that it is a custom UserHandle, so it's ok to ignore the error
userID, _ = uuid.FromBytes(credentialAssertionData.Response.UserHandle)
}

webAuthnUser, userModel, err := s.GetWebAuthnUser(p.Tx, *credentialModel, userID)
Expand Down Expand Up @@ -352,12 +351,13 @@ func (s *webauthnService) VerifyAttestationResponse(p VerifyAttestationResponseP
}

func (s *webauthnService) GetWebAuthnUser(tx *pop.Connection, credential models.WebauthnCredential, userID uuid.UUID) (webauthn.User, *models.User, error) {
var customUserHandle *string = nil
var customUserHandle []byte = nil
if userID == uuid.Nil {
userID = credential.UserId
if credential.UserHandle != nil {
customUserHandle = &credential.UserHandle.Handle
}
}

if credential.UserHandle != nil {
customUserHandle = []byte(credential.UserHandle.Handle)
}

user, err := s.persister.GetUserPersisterWithConnection(tx).Get(userID)
Expand All @@ -370,7 +370,7 @@ func (s *webauthnService) GetWebAuthnUser(tx *pop.Connection, credential models.

if customUserHandle != nil {
return &webauthnUserWithCustomUserHandle{
CustomUserHandle: *customUserHandle,
CustomUserHandle: customUserHandle,
User: *user,
}, user, nil
}
Expand All @@ -380,9 +380,9 @@ func (s *webauthnService) GetWebAuthnUser(tx *pop.Connection, credential models.

type webauthnUserWithCustomUserHandle struct {
models.User
CustomUserHandle string
CustomUserHandle []byte
}

func (u *webauthnUserWithCustomUserHandle) WebAuthnID() []byte {
return []byte(u.CustomUserHandle)
return u.CustomUserHandle
}

0 comments on commit 58a0397

Please sign in to comment.