Documentation
¶
Overview ¶
Package stdwebauthn provides web client authentication.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAnonymous ¶
Types ¶
type Anonymous ¶
type Anonymous struct{}
Anonymous represents an identity that is not authenticated. We do not know who this is.
func (Anonymous) MarshalJSON ¶
func (Anonymous) UnmarshalJSON ¶
type Authenticated ¶
type Authenticated struct {
// contains filtered or unexported fields
}
Authenticated repesent an authenticated identity. We know who this is.
func NewAuthenticated ¶
func NewAuthenticated(id string, email string) Authenticated
func (Authenticated) Email ¶
func (idn Authenticated) Email() string
func (Authenticated) ID ¶
func (idn Authenticated) ID() string
func (Authenticated) MarshalJSON ¶
func (idn Authenticated) MarshalJSON() ([]byte, error)
func (Authenticated) String ¶
func (idn Authenticated) String() string
func (*Authenticated) UnmarshalJSON ¶
func (idn *Authenticated) UnmarshalJSON(data []byte) error
type Authentication ¶
type Authentication struct {
// contains filtered or unexported fields
}
Authentication provides authentication of web clients.
func (*Authentication) Callback ¶
func (a *Authentication) Callback() (string, bhttp.HandlerFunc[context.Context])
Callback implements the return of the client from the provider.
func (*Authentication) Login ¶
func (a *Authentication) Login() (string, bhttp.HandlerFunc[context.Context])
Login implements the start of the authentication flow.
func (*Authentication) Logout ¶
func (a *Authentication) Logout() (string, bhttp.HandlerFunc[context.Context])
func (*Authentication) SessionMiddleware ¶
func (a *Authentication) SessionMiddleware() bhttp.Middleware
SessionMiddleware provides the middleware that reads the session information for every request that passes through the server.
type Backend ¶
type Backend interface {
AuthenticateCode(
ctx context.Context,
provider Provider,
code string,
) (Identity, error)
}
Backend implements an authentication backend.
func NewFixedIdentityBackend ¶
type Config ¶
type Config struct {
// configure which social providers are enabled.
EnabledProviders []string `env:"ENABLED_PROVIDERS"`
// configure the exterior url clients will be re-directed back to.
BaseCallbackURL string `env:"BASE_CALLBACK_URL,required"`
// SessionKeyPairs configures the keys used for signing en encrypting the session cookies.
SessionKeyPairs []stdenvcfg.HexBytes `env:"SESSION_KEY_PAIRS"`
// the max age of the session cookie, in seconds. Defaults to a year.
SessionDefaultMaxAgeSeconds int64 `env:"SESSION_DEFAULT_MAX_AGE_SECONDS" envDefault:"31556926"`
// how long the session that keeps state between login and callback remains valid.
StateMaxAgeSeconds int `env:"STATE_MAX_AGE_SECONDS" envDefault:"3600"`
// name of the cookie used to keep the auth (flow) state from login to callback.
StateCookieName string `env:"STATE_COOKIE_NAME" envDefault:"AUTHSTATE"`
// name of the cookie used to keep the user's session between requests.
SessionCookieName string `env:"SESSION_COOKIE_NAME" envDefault:"AUTHSESS"`
// white list of hosts where the backend will redirect to.
AllowedRedirectHosts []string `env:"ALLOWED_REDIRECT_HOSTS"`
// configuration for each supported social provider.
Google providerConfig `envPrefix:"GOOGLE_"`
LinkedIn providerConfig `envPrefix:"LINKEDIN_"`
Microsoft providerConfig `envPrefix:"MICROSOFT_"`
}
Config configures the package's components.
type Identity ¶
func IdentityFromContext ¶
type Provider ¶
type Provider interface {
Kind() ProviderKind
OAuth() *oauth2.Config
OIDC() *oidc.Provider
}
Provider is what the provider.
type ProviderKind ¶
type ProviderKind int
const ( ProviderKindUnknown ProviderKind = iota ProviderKindLinkedIn ProviderKindGoogle ProviderKindMicrosoft )
func (ProviderKind) String ¶
func (pk ProviderKind) String() string
Click to show internal directories.
Click to hide internal directories.