Skip to content

Commit

Permalink
feat(webauthn): add passwordless credentials indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Mar 7, 2022
1 parent 303dc6b commit 6e3057a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion selfservice/strategy/webauthn/credentials.go
Expand Up @@ -10,14 +10,16 @@ import (
type CredentialsConfig struct {
// List of webauthn credentials.
Credentials Credentials `json:"credentials"`
UserHandle []byte `json:"user_handle"`
}

type Credentials []Credential

func CredentialFromWebAuthn(credential *webauthn.Credential) *Credential {
func CredentialFromWebAuthn(credential *webauthn.Credential, isPasswordless bool) *Credential {
return &Credential{
ID: credential.ID,
PublicKey: credential.PublicKey,
IsPasswordless: isPasswordless,
AttestationType: credential.AttestationType,
Authenticator: Authenticator{
AAGUID: credential.Authenticator.AAGUID,
Expand Down Expand Up @@ -55,6 +57,7 @@ type Credential struct {
Authenticator Authenticator `json:"authenticator"`
DisplayName string `json:"display_name"`
AddedAt time.Time `json:"added_at"`
IsPasswordless bool `json:"is_passwordless"`
}

type Authenticator struct {
Expand Down
9 changes: 7 additions & 2 deletions selfservice/strategy/webauthn/credentials_test.go
Expand Up @@ -19,9 +19,14 @@ func TestCredentialConversion(t *testing.T) {
},
}

actual := CredentialFromWebAuthn(expected).ToWebAuthn()
actual := CredentialFromWebAuthn(expected, false).ToWebAuthn()
assert.Equal(t, expected, actual)

actualList := Credentials{*CredentialFromWebAuthn(expected)}.ToWebAuthn()
actualList := Credentials{*CredentialFromWebAuthn(expected, false)}.ToWebAuthn()
assert.Equal(t, []webauthn.Credential{*expected}, actualList)

fromWebAuthn := CredentialFromWebAuthn(expected, true)
assert.True(t, fromWebAuthn.IsPasswordless)
fromWebAuthn = CredentialFromWebAuthn(expected, false)
assert.False(t, fromWebAuthn.IsPasswordless)
}

0 comments on commit 6e3057a

Please sign in to comment.