package storage import ( "time" "github.com/go-webauthn/webauthn/webauthn" ) type UserHeader struct { ID string `json:"id"` Username string `json:"username"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } type User struct { UserHeader Attributes map[string]any `json:"attributes"` Credentials []webauthn.Credential `json:"credentials"` } // WebAuthnCredentials implements webauthn.User. func (u *User) WebAuthnCredentials() []webauthn.Credential { return u.Credentials } // WebAuthnDisplayName implements webauthn.User. func (u *User) WebAuthnDisplayName() string { return u.Username } // WebAuthnID implements webauthn.User. func (u *User) WebAuthnID() []byte { return []byte(u.ID) } // WebAuthnIcon implements webauthn.User. func (u *User) WebAuthnIcon() string { return "" } // WebAuthnName implements webauthn.User. func (u *User) WebAuthnName() string { return u.Username } func NewUser(username string, attributes map[string]any) *User { now := time.Now() return &User{ UserHeader: UserHeader{ ID: NewID(), Username: username, CreatedAt: now, UpdatedAt: now, }, Attributes: attributes, Credentials: make([]webauthn.Credential, 0), } } var _ webauthn.User = &User{}