passkey

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePasskeyChallenge

func CreatePasskeyChallenge(challenge PasskeyChallenge) error

func CreatePasskeyCredential

func CreatePasskeyCredential(cred PasskeyCredential) error

func CredentialsToWebAuthn

func CredentialsToWebAuthn(creds []PasskeyCredential) []webauthn.Credential

CredentialsToWebAuthn converts stored PasskeyCredentials to webauthn.Credential slice.

func DeletePasskeyCredential

func DeletePasskeyCredential(credentialID string) error

func HandleLoginBegin

func HandleLoginBegin(w http.ResponseWriter, r *http.Request)

HandleLoginBegin starts a passkey authentication ceremony. @Summary Begin passkey login @Description Initiates a WebAuthn authentication ceremony. The user must already have a registered passkey. Returns the options for the navigator.credentials.get call. @Tags passkey @Accept json @Produce json @Param username query string true "User's username" @Param redirect_uri query string false "Redirect URI" @Param state query string false "OAuth2 state" @Param client_id query string false "OAuth2 client ID" @Success 200 {object} map[string]any "WebAuthn assertion options" @Router /oauth2/passkey/login/begin [get]

func HandleLoginFinish

func HandleLoginFinish(w http.ResponseWriter, r *http.Request)

HandleLoginFinish completes a passkey authentication ceremony. @Summary Complete passkey login @Description Processes the WebAuthn assertion from the client and issues an authorization code. @Tags passkey @Accept json @Produce json @Param challenge_id query string true "Challenge ID from BeginLogin" @Param assertion body map[string]any true "WebAuthn assertion response" @Success 200 {object} map[string]string "Redirect URL" @Router /oauth2/passkey/login/finish [post]

func HandleRegisterFinish

func HandleRegisterFinish(w http.ResponseWriter, r *http.Request)

HandleRegisterFinish completes a passkey registration ceremony. @Summary Complete passkey registration @Description Processes the WebAuthn attestation from the client and registers the passkey. @Tags passkey @Accept json @Produce json @Param challenge_id query string true "Challenge ID from BeginRegistration" @Param attestation body map[string]any true "WebAuthn attestation response" @Success 200 {object} map[string]string "Redirect URL" @Router /oauth2/passkey/register/finish [post]

func MarkPasskeyChallengeUsed

func MarkPasskeyChallengeUsed(id string) error

func NewWebAuthn

func NewWebAuthn() (*webauthn.WebAuthn, error)

NewWebAuthn creates a WebAuthn instance from the current config.

func UpdatePasskeyCredential

func UpdatePasskeyCredential(credentialID string, cred webauthn.Credential) error

UpdatePasskeyCredential stores the updated credential (e.g. new sign count) and sets last_used_at.

Types

type LoginState

type LoginState struct {
	RedirectURI         string `json:"redirect_uri"`
	State               string `json:"state"`
	ClientID            string `json:"client_id"`
	Scope               string `json:"scope"`
	Nonce               string `json:"nonce"`
	CodeChallenge       string `json:"code_challenge"`
	CodeChallengeMethod string `json:"code_challenge_method"`
}

type PasskeyChallenge

type PasskeyChallenge struct {
	ID            string
	UserID        string
	ChallengeData string // JSON-encoded webauthn.SessionData
	Type          string // "registration" or "authentication"
	LoginState    string // JSON-encoded LoginState
	CreatedAt     time.Time
	ExpiresAt     time.Time
	Used          bool
}

func PasskeyChallengeByID

func PasskeyChallengeByID(id string) (*PasskeyChallenge, error)

type PasskeyCredential

type PasskeyCredential struct {
	ID         string
	UserID     string
	Name       string
	Credential string // JSON-encoded webauthn.Credential
	CreatedAt  time.Time
	LastUsedAt *time.Time
}

func PasskeyCredentialsByUserID

func PasskeyCredentialsByUserID(userID string) ([]PasskeyCredential, error)

type WebAuthnUser

type WebAuthnUser struct {
	ID          []byte
	Name        string
	Credentials []webauthn.Credential
}

WebAuthnUser implements the webauthn.User interface.

func (WebAuthnUser) WebAuthnCredentials

func (u WebAuthnUser) WebAuthnCredentials() []webauthn.Credential

func (WebAuthnUser) WebAuthnDisplayName

func (u WebAuthnUser) WebAuthnDisplayName() string

func (WebAuthnUser) WebAuthnID

func (u WebAuthnUser) WebAuthnID() []byte

func (WebAuthnUser) WebAuthnName

func (u WebAuthnUser) WebAuthnName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL