Documentation
¶
Overview ¶
Package store has the interfaces of what an identity is exchanged with: a hook, which allows it, or refuses it, the users, which say who it is, and the scopes they have, and the sessions, which they're signed in with, and the exchanger, which exchanges an identity for a session.
Index ¶
Constants ¶
const DefaultTTL = 24 * time.Hour
DefaultTTL is how long a session lasts, without WithTTL
Variables ¶
This section is empty.
Functions ¶
func IdentityID ¶
IdentityID returns the ID of an identity's user, without a user store: its issuer and subject, which are what identify it, each escaped, so there's one for each, and it doesn't change when the provider, which is configured, is renamed
func ResponseSchema ¶
func ResponseSchema() *jsonschema.Schema
ResponseSchema is the schema of what an identity is exchanged for, which is the response of signing in
Types ¶
type Consumer ¶
type Consumer interface {
// Consume consumes the ID, until it expires, or returns conflict,
// when it's been consumed
Consume(ctx context.Context, id string, expires time.Time) error
}
Consumer consumes values which are used once, such as authorization codes, by their IDs, until they expire, so one isn't used again by another server which shares the store, or after a restart. A session store can be one.
type Exchanger ¶
type Exchanger struct {
// contains filtered or unexported fields
}
Exchanger exchanges an identity for a session: when the hook allows it, for the user it is, which a user store says, with their scopes, which the session has, until it expires
func NewExchanger ¶
func NewExchanger(sessions SessionStore, opts ...Opt) (*Exchanger, error)
NewExchanger returns an exchanger, which keeps sessions in the store. Without a user store, the user is the identity, without scopes, and without a hook, every identity is allowed.
type Hook ¶
Hook is user-defined: it says whether an identity can be exchanged for a session, such as only one with an email address at a domain, and refuses one with an error, such as forbidden
func AllowDomains ¶
AllowDomains returns a hook, which only allows identities with a verified email address at one of the domains, such as example.com, in any case
type Opt ¶
Opt is an option of an exchanger
type SessionStore ¶
type SessionStore interface {
// Create keeps a new session, whose ID and creation are set, and
// returns its token, which is only returned now
Create(ctx context.Context, session schema.Session) (*schema.SessionToken, error)
// Session returns the session of a token, or not authorized, when there
// isn't one, or it's expired
Session(ctx context.Context, token string) (*schema.Session, error)
// Revoke removes the session with the ID, or returns not found
Revoke(ctx context.Context, id string) error
}
SessionStore keeps sessions, by a hash of their tokens, which aren't kept
type UserStore ¶
type UserStore interface {
// User returns the user an identity is, or not found, when it isn't
// one of the store's users
User(ctx context.Context, identity *schema.Identity) (*schema.User, error)
// Scopes returns the scopes a user has
Scopes(ctx context.Context, user *schema.User) ([]string, error)
}
UserStore says who an identity is, and the scopes they have