-
Notifications
You must be signed in to change notification settings - Fork 940
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
Feat custom user #1978
Feat custom user #1978
Conversation
Add custom user ID to a user. This custom user ID is only used for verifying assertions from imported passkeys.
Change the DB schema to restrict a user handle to only one user.
@@ -354,3 +350,39 @@ func (s *webauthnService) VerifyAttestationResponse(p VerifyAttestationResponseP | |||
|
|||
return credential, nil | |||
} | |||
|
|||
func (s *webauthnService) GetWebAuthnUser(tx *pop.Connection, credential models.WebauthnCredential, userID uuid.UUID) (webauthn.User, *models.User, error) { | |||
var customUserHandle *string = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that it is only possible to use (custom) user handles that are not UUID's. I would have expected that UserHandle.Handle
is used when assigned to the related credential, the User.ID
otherwise, so that the logic would look something like this:
var webAuthnID []bytes
if credentialModel.UserHandle != nil {
webAuthnID = []byte(credentialModel.UserHandle.Handle)
} else {
webAuthnID = credentialModel.User.ID.Bytes()
}
@@ -90,7 +90,7 @@ func NewManager(jwkManager hankoJwk.Manager, config config.Config) (Manager, err | |||
} | |||
|
|||
// GenerateJWT creates a new session JWT for the given user | |||
func (m *manager) GenerateJWT(userId uuid.UUID, email *dto.EmailJwt) (string, jwt.Token, error) { | |||
func (m *manager) GenerateJWT(userId uuid.UUID, email *dto.EmailJwt, opts ...JWTOptions) (string, jwt.Token, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make sense to set the email
parameter via a JWTOption
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would make sense. This is just leftover from the previous implementation where a user would have a custom userID. And I forgot that its still there. Maybe we can do it in a separate PR?
backend/persistence/migrations/20241118114500_change_webauthn_credentials.up.fizz
Outdated
Show resolved
Hide resolved
backend/persistence/migrations/20241118114500_change_webauthn_credentials.up.fizz
Outdated
Show resolved
Hide resolved
Co-authored-by: bjoern-m <[email protected]>
Co-authored-by: bjoern-m <[email protected]>
Description
Add custom user handle to a webauthn credential. This custom user handle is only used for verifying assertions from imported passkeys.
New passkeys are created with the user id (uuid) from Hanko.
Implementation
Added a new column to the webauthn credentials table. Check in
WebauthnService.VerifyAssertionResponse
if the userHandle in the response is a uuid, if not treat it as a custom user handle. Get the user based on the credential ID verify the response against the user credentialsTests
Keep in mind that the webauthn credential must be created and used with the same RP ID.
Todos
Additional context
This is needed when a relying party already has implemented passkeys, but wants to migrate to Hanko and does not use uuids as user identifiers.