Documentation
¶
Overview ¶
Package oidc signs people in through the organization's OpenID Connect provider. It keeps who they are in a session, and tells the framework who sends each request: it has an Authenticator of the framework (server.Authenticator), the routes of signing in and out, and a wrapper for the pages that need a person.
Package serve uses it. https://i2y.github.io/ringi-server/sign-in/ says how to connect a provider, and DESIGN.md how it works.
Index ¶
Constants ¶
const ( DefaultSkew = time.Minute DefaultSessionLimit = 12 * time.Hour DefaultIdleLimit = 2 * time.Hour )
The defaults of Config.
const ( SessionCookie = "__Host-ringi-session" SignInCookie = "__Host-ringi-signin-" )
The names of the cookies: the session, and a sign-in under way (followed by the first 16 characters of its state).
Variables ¶
var ( ErrNoVerifiedEmail = &Refusal{Reason: "no_verified_email", Words: map[string]string{ "en": "Your organization's account has no confirmed email address, so this server cannot tell who you are. Ask the people who manage the accounts.", "ja": "組織のアカウントに確認済みのメールアドレスが無いため、このサーバーではあなたが誰かを確かめられません。アカウントの管理者に相談してください。", }} ErrNotInOrganization = &Refusal{Reason: "not_in_organization", Words: map[string]string{ "en": "No one in the organization's data has your email address, so you cannot use this server yet. Ask the people who keep the organization's data to add you.", "ja": "組織のデータに、あなたのメールアドレスの人がいません。そのため、まだこのサーバーを使えません。組織のデータを管理している人に、登録を頼んでください。", }} ErrAmbiguousEmail = &Refusal{Reason: "ambiguous_email", Words: map[string]string{ "en": "More than one person in the organization's data has your email address, so this server cannot tell which one you are. Ask the people who keep the organization's data to correct it.", "ja": "組織のデータに、あなたのメールアドレスの人が二人以上います。そのため、どの人かを決められません。組織のデータを管理している人に、直すよう頼んでください。", }} )
The refusals of ByEmail.
Functions ¶
Types ¶
type Claims ¶
type Claims struct {
Issuer string
Subject string
// Email is the token's email, and EmailVerified whether the token says the provider verified
// it (the JSON boolean true).
Email string
EmailVerified bool
Name string
// All are every claim of the token, as it writes them.
All map[string]json.RawMessage
}
Claims are the claims of an ID token that passed every check.
type Config ¶
type Config struct {
// Issuer is the provider's issuer URL, exactly as its discovery document writes it.
Issuer string
// ClientID and ClientSecret are the client's, as the provider registered it.
ClientID string
ClientSecret string
// ClientAuth is how the client proves itself at the token endpoint: "client_secret_basic"
// (when "") or "client_secret_post".
ClientAuth string
// RedirectURL is the callback's URL, as registered at the provider. The callback is served at
// its path.
RedirectURL string
// Scopes are the scopes asked for: "openid email profile" when nil ("openid" is added when
// missing).
Scopes []string
// Params are more parameters of the authorization request (prompt, login_hint…).
Params url.Values
// Algorithms are the algorithms an ID token may be signed with: RS256, PS256 and ES256 when
// nil.
Algorithms []string
// Audiences are the audiences an ID token may name besides the client ID.
Audiences []string
// Skew is how far the provider's clock may be from the server's: 1 minute when 0, none when
// negative.
Skew time.Duration
// Keys are the keys of the cookies, 32 random bytes each: the first seals, every one opens. New
// refuses a key that is text or repeats its bytes, and a key given twice.
Keys [][]byte
// SessionLimit is the longest a session lasts from the sign-in: 12 hours when 0.
SessionLimit time.Duration
// IdleLimit is the longest a session lasts unused: 2 hours when 0, none when negative.
IdleLimit time.Duration
// Revocations, when given, keeps the sessions ended before their limits.
Revocations Revocations
// Map makes the framework's person from the claims of an ID token that passed every check.
Map Map
// LoginPath and LogoutPath are the paths of signing in and out: /login and /logout when "".
LoginPath, LogoutPath string
// AfterLogout is where signing out sends a browser: / when "".
AfterLogout string
// ProviderLogout sends a person who signs out on to the provider's end_session_endpoint;
// PostLogoutRedirectURL is where the provider sends them back (registered there; none when "").
ProviderLogout bool
PostLogoutRedirectURL string
// HTTPClient makes the calls to the provider: a client with a 10-second timeout when nil.
HTTPClient *http.Client
// Clock tells the time: the system's when nil.
Clock server.Clock
// Logger is slog.Default() when nil.
Logger *slog.Logger
}
Config is what New is made with (DESIGN.md, section 9).
type Map ¶
Map makes the framework's person from the claims of an ID token that passed every check. A *Refusal keeps the person from signing in, with the words they are shown; any other error is a failure (500).
type MemoryRevocations ¶
type MemoryRevocations struct {
// contains filtered or unexported fields
}
MemoryRevocations keeps the ended sessions in memory: for a server of one process, and for tests.
func NewMemoryRevocations ¶
func NewMemoryRevocations() *MemoryRevocations
NewMemoryRevocations makes an empty MemoryRevocations.
type Mux ¶
Mux is what Mount adds the routes to: an *http.ServeMux, or the screens' handler (web.Handler), which puts them behind its guards.
type Refusal ¶
type Refusal struct {
Reason string
// Words are the words shown, by language: "en", and "ja" when there are Japanese ones.
Words map[string]string
}
Refusal is what a Map answers to keep a person from signing in: the person is shown Words in their language (English when there are none of theirs), with 403, and Reason is logged.
type Revocations ¶
type Revocations interface {
// Revoke records that the session has ended; until is when it would have ended anyway, after
// which the record may be dropped.
Revoke(ctx context.Context, session string, until time.Time) error
// Revoked reports whether the session was recorded as ended.
Revoked(ctx context.Context, session string) (bool, error)
}
Revocations keeps the sessions ended before their limits (DESIGN.md, 6.4).
type SignIn ¶
type SignIn struct {
// contains filtered or unexported fields
}
SignIn signs people in through one provider and finds them in their sessions. It is safe for use by many goroutines at once.
func New ¶
New makes a SignIn: it checks the configuration, then reads the provider's discovery document and its keys.
func (*SignIn) Authenticate ¶
Authenticate answers the person of the request's session: server.ErrNoPerson when there is none, it does not open, or it has ended. It is the framework's Authenticator.
func (*SignIn) LoginURL ¶
LoginURL answers the address of signing in that comes back to returnTo, a path of this server (/ when it is not one).
func (*SignIn) Mount ¶
Mount adds the routes of signing in and out: GET Config.LoginPath, GET the redirect URL's path (the callback), and POST Config.LogoutPath.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package oidctest is an OpenID Connect provider for the tests of a server that signs people in with package oidc: its discovery document, a JWK Set, an authorization endpoint that signs in at once the person a test chooses, and a token endpoint that checks the client, the redirect URL, PKCE and that a code is used once, and signs ID tokens with an RSA key (RS256).
|
Package oidctest is an OpenID Connect provider for the tests of a server that signs people in with package oidc: its discovery document, a JWK Set, an authorization endpoint that signs in at once the person a test chooses, and a token endpoint that checks the client, the redirect URL, PKCE and that a code is used once, and signs ID tokens with an RSA key (RS256). |