Skip to content

Commit

Permalink
fix: also offer passkey on duplicate cred err
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Apr 26, 2024
1 parent 81dd37c commit 189f8b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions identity/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ func (m *Manager) findExistingAuthMethod(ctx context.Context, e error, i *Identi
identifierHint = cred.Identifiers[0]
}

for _, webauthn := range cfg.Credentials {
if webauthn.IsPasswordless {
duplicateCredErr.AddCredentialsType(cred.Type)
duplicateCredErr.SetIdentifierHint(identifierHint)
break
}
}
case CredentialsTypePasskey:
var cfg CredentialsWebAuthnConfig
if err := json.Unmarshal(cred.Config, &cfg); err != nil {
return errors.WithStack(herodot.ErrInternalServerError.WithReasonf("Unable to JSON decode identity credentials %s for identity %s.", cred.Type, found.ID))

Check warning on line 256 in identity/manager.go

View check run for this annotation

Codecov / codecov/patch

identity/manager.go#L256

Added line #L256 was not covered by tests
}

identifierHint := foundConflictAddress
if len(cred.Identifiers) > 0 {
identifierHint = cred.Identifiers[0]
}

for _, webauthn := range cfg.Credentials {
if webauthn.IsPasswordless {
duplicateCredErr.AddCredentialsType(cred.Type)
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/oidc/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ func TestStrategy(t *testing.T) {
var linkingLoginFlow struct{ ID string }
t.Run("step=should fail login and start a new login", func(t *testing.T) {
res, body := loginWithOIDC(t, client, loginFlow.ID, "valid")
assertUIError(t, res, body, "You tried signing in with [email protected] which is already in use by another account. You can sign in using social sign in, or your password. You can sign in using one of the following social sign in providers: Secondprovider.")
assertUIError(t, res, body, "You tried signing in with [email protected] which is already in use by another account. You can sign in using social sign in. You can sign in using one of the following social sign in providers: Secondprovider.")
linkingLoginFlow.ID = gjson.GetBytes(body, "id").String()
assert.NotEqual(t, loginFlow.ID.String(), linkingLoginFlow.ID, "should have started a new flow")
})
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/passkey/passkey_registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func TestRegistration(t *testing.T) {
assert.Contains(t, gjson.Get(actual, "ui.action").String(), fix.publicTS.URL+registration.RouteSubmitFlow, "%s", actual)
registrationhelpers.CheckFormContent(t, []byte(actual), "csrf_token", "traits.username")
assert.Equal(t,
"You tried signing in with "+email+" which is already in use by another account.",
"You tried signing in with "+email+" which is already in use by another account. You can sign in using your passkey.",
gjson.Get(actual, "ui.messages.0.text").String(), "%s", actual)
})
}
Expand Down
2 changes: 2 additions & 0 deletions text/message_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ func NewErrorValidationDuplicateCredentialsWithHints(availableCredentialTypes []
humanReadable = append(humanReadable, "social sign in")
case "webauthn":
humanReadable = append(humanReadable, "your passkey or a security key")
case "passkey":
humanReadable = append(humanReadable, "your passkey")
}
}
if len(humanReadable) == 0 {
Expand Down

0 comments on commit 189f8b4

Please sign in to comment.