Documentation
¶
Overview ¶
Package identity defines the identity provider interface. The provider owns credentials and sessions. C4Stack maps each identity to a local account by provider name and subject, and joins a new identity to the account that has its verified email address.
Index ¶
Constants ¶
View Source
const RecentSignIn = 5 * time.Minute
RecentSignIn is how old a session may be for actions that need the owner to be present, such as deleting the account or changing passkeys.
Variables ¶
View Source
var ErrNoSession = errors.New("identity: no valid session")
ErrNoSession means the request carries no valid session.
Functions ¶
Types ¶
type Identity ¶
type Identity struct {
// Subject is the provider's stable user ID.
Subject string
// Email is the user's primary address. EmailVerified reports whether the provider
// verified it; an unverified identity cannot sign in to an account.
Email string
EmailVerified bool
// SignedInAt is when the session was created.
SignedInAt time.Time
}
Identity is the signed-in user as the provider reports it.
func FromContext ¶
FromContext returns the identity stored by NewContext.
type Provider ¶
type Provider interface {
// Name identifies the provider in stored accounts, such as "hanko". It must not
// change once accounts exist.
Name() string
// Authenticate validates the request's session. It returns ErrNoSession when there
// is none or it is no longer valid.
Authenticate(r *http.Request) (Identity, error)
// Logout ends the request's session at the provider and clears it in the browser.
// It clears the browser session even when the provider cannot be reached.
Logout(w http.ResponseWriter, r *http.Request) error
// Delete deletes the signed-in user at the provider. It returns nil only once the
// provider has confirmed the deletion.
Delete(ctx context.Context, r *http.Request) error
}
Provider is an identity provider such as Hanko.
Click to show internal directories.
Click to hide internal directories.