Skip to content

Commit

Permalink
ensure name is unique
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerNoblett committed Aug 31, 2023
1 parent 25da6c0 commit 724e6c0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions backend/authschemes/webauthn/webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,22 @@ func (a WebAuthn) beginRegistration(w http.ResponseWriter, r *http.Request, brid
user = makeAddCredentialWebAuthnUser(info.UserID, info.Username, info.CredentialName, info.ExistingCredentials)
}

idx, _ := helpers.Find(info.ExistingCredentials, func(cred AShirtWebauthnCredential) bool {
return strings.ToLower(cred.CredentialName) == strings.ToLower(info.CredentialName)
})

if idx != -1 {
return nil, errors.New("Credential name is already taken")
}

credExcludeList := make([]protocol.CredentialDescriptor, len(user.Credentials))
for i, cred := range user.Credentials {
credExcludeList[i] = protocol.CredentialDescriptor{
Type: protocol.PublicKeyCredentialType,
CredentialID: cred.ID,
}
}
// TODO TN can I iterate on the lit I have in the old PR in a similar way?
registrationOptions := func(credCreationOpts *protocol.PublicKeyCredentialCreationOptions) {
credCreationOpts.CredentialExcludeList = credExcludeList
}
Expand Down

0 comments on commit 724e6c0

Please sign in to comment.