Help us shape the future of Go! Take the 2026 Go Developer Survey

identity

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

func NewContext

func NewContext(ctx context.Context, id Identity) context.Context

NewContext returns a context carrying the signed-in identity.

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

func FromContext(ctx context.Context) (Identity, bool)

FromContext returns the identity stored by NewContext.

func (Identity) Recent

func (id Identity) Recent(now time.Time) bool

Recent reports whether the session was created within RecentSignIn of now.

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.

Directories

Path Synopsis
Package hanko is the Hanko identity provider adapter.
Package hanko is the Hanko identity provider adapter.

Jump to

Keyboard shortcuts

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