Documentation ¶
Index ¶
- Constants
- Variables
- func BytesToID(buf []byte) uint
- func CreateCredential(c *Credential) error
- func DeleteCredentialByID(credentialID string) error
- func PutUser(u *User) error
- func Setup(config *config.Config) error
- func UpdateAuthenticatorSignCount(id uint, count uint32) error
- func UpdateCredential(c *Credential) error
- type Authenticator
- type Credential
- type User
Constants ¶
const PlaceholderUserIcon = "example.icon.duo.com/123/avatar.png"
PlaceholderUserIcon is the default user icon used when creating a new user
const PlaceholderUsername = "testuser"
PlaceholderUsername is the default username to use if one isn't provided by the user (in the case of a placeholder)
Variables ¶
var ErrUsernameTaken = errors.New("username already taken")
ErrUsernameTaken is thrown when a user attempts to register a username that is taken.
Functions ¶
func BytesToID ¶
BytesToID converts a byte slice to a uint. This is needed because the WebAuthn specification deals with byte buffers, while the primary keys in our database are uints.
func CreateCredential ¶
func CreateCredential(c *Credential) error
CreateCredential creates a new credential object
func DeleteCredentialByID ¶
DeleteCredentialByID gets a credential by its ID. In practice, this would be a bad function without some other checks (like what user is logged in) because someone could hypothetically delete ANY credential.
func UpdateAuthenticatorSignCount ¶
UpdateAuthenticatorSignCount updates a specific authenticator's sign count for tracking potential clone attempts.
func UpdateCredential ¶
func UpdateCredential(c *Credential) error
UpdateCredential updates the credential with new attributes.
Types ¶
type Authenticator ¶
type Authenticator struct { gorm.Model webauthn.Authenticator }
Authenticator is a struct representing a WebAuthn authenticator, which is responsible for generating Credentials. For this demo, we map a single credential to a single authenticator.
func CreateAuthenticator ¶
func CreateAuthenticator(a webauthn.Authenticator) (Authenticator, error)
CreateAuthenticator creates a new authenticator that's tied to a Credential.
func GetAuthenticator ¶
func GetAuthenticator(id uint) (Authenticator, error)
GetAuthenticator returns the authenticator the given id corresponds to. If no authenticator is found, an error is thrown.
type Credential ¶
type Credential struct { gorm.Model CredentialID string `json:"credential_id"` User User `json:"-"` UserID uint `json:"-"` Authenticator Authenticator `json:"authenticator"` AuthenticatorID uint `json:"authenticator_id"` PublicKey []byte `json:"public_key,omitempty"` }
Credential is the stored credential for Auth
func GetCredentialForUser ¶
func GetCredentialForUser(user *User, credentialID string) (Credential, error)
GetCredentialForUser retrieves a specific credential for a user.
func GetCredentialsForUser ¶
func GetCredentialsForUser(user *User) ([]Credential, error)
GetCredentialsForUser retrieves all credentials for a provided user regardless of relying party.
func (*Credential) DisplayPublicKey ¶
func (c *Credential) DisplayPublicKey() string
func (*Credential) WebauthnAuthenticator ¶
func (c *Credential) WebauthnAuthenticator() webauthn.Authenticator
WebauthnAuthenticator returns the underlying authenticator used to generate the credential.
type User ¶
type User struct { gorm.Model Username string `json:"name" sql:"not null;"` DisplayName string `json:"display_name"` Icon string `json:"icon,omitempty"` Credentials []Credential `json:"credentials,omitempty"` }
User represents the user model.
func GetUser ¶
GetUser returns the user that the given id corresponds to. If no user is found, an error is thrown.
func GetUserByUsername ¶
GetUserByUsername returns the user that the given username corresponds to. If no user is found, an error is thrown.
func (User) WebAuthnCredentials ¶
func (u User) WebAuthnCredentials() []webauthn.Credential
WebAuthnCredentials helps implement the webauthn.User interface by loading the user's credentials from the underlying database.
func (User) WebAuthnDisplayName ¶
WebAuthnDisplayName returns the user's display name
func (User) WebAuthnID ¶
WebAuthnID returns the user ID as a byte slice
func (User) WebAuthnName ¶
WebAuthnName returns the user's username