mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-28 23:30:15 +08:00
* feat: add custom user ID Add custom user ID to a user. This custom user ID is only used for verifying assertions from imported passkeys. * test: fix build * feat: add new user properties to import * feat: improve error messages on import * feat: add customUserHandle to webauthn credential * chore: change DB schema for user handle Change the DB schema to restrict a user handle to only one user. * fix: add missing value in sql migration statement * chore: remove unused variables Co-authored-by: bjoern-m <56024829+bjoern-m@users.noreply.github.com> * chore: change migration Co-authored-by: bjoern-m <56024829+bjoern-m@users.noreply.github.com> * fix: always use custom user handle if available * chore: simplify getting the webauthn user * fix: fix unique constraint on user handle Apply unique constraint to the column handle in table webauthn_credential_user_handles. * feat: add custom user handle to user import * chore: typos * fix: fix user import with multiple credentials Fix user import with multiple credential and the same user handle. Check if the user handle already exists and associate the credential with it otherwise create a new user handle in the database. --------- Co-authored-by: bjoern-m <56024829+bjoern-m@users.noreply.github.com>
35 lines
939 B
Go
35 lines
939 B
Go
package persistence
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"fmt"
|
|
"github.com/gobuffalo/pop/v6"
|
|
"github.com/teamhanko/hanko/backend/persistence/models"
|
|
)
|
|
|
|
type WebauthnCredentialUserHandlePersister interface {
|
|
GetByHandle(string) (*models.WebauthnCredentialUserHandle, error)
|
|
}
|
|
|
|
func NewWebauthnCredentialUserHandlePersister(db *pop.Connection) WebauthnCredentialUserHandlePersister {
|
|
return &webauthnCredentialUserHandlePersister{db: db}
|
|
}
|
|
|
|
type webauthnCredentialUserHandlePersister struct {
|
|
db *pop.Connection
|
|
}
|
|
|
|
func (p *webauthnCredentialUserHandlePersister) GetByHandle(handle string) (*models.WebauthnCredentialUserHandle, error) {
|
|
handleModel := models.WebauthnCredentialUserHandle{}
|
|
err := p.db.Where("handle = ?", handle).First(&handleModel)
|
|
if err != nil && errors.Is(err, sql.ErrNoRows) {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get handleModel: %w", err)
|
|
}
|
|
|
|
return &handleModel, nil
|
|
}
|