store

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const DefaultTTL = 24 * time.Hour

DefaultTTL is how long a session lasts, without WithTTL

Variables

This section is empty.

Functions

func IdentityID

func IdentityID(identity *schema.Identity) string

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.

func (*Exchanger) Exchange

func (e *Exchanger) Exchange(ctx context.Context, identity *schema.Identity) (any, error)

Exchange exchanges an identity for a session, and returns its token. A hook's error refuses it, as does an identity which isn't a user, which is forbidden.

type Hook

type Hook func(ctx context.Context, identity *schema.Identity) error

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

func AllowDomains(domains ...string) Hook

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

type Opt func(*Exchanger) error

Opt is an option of an exchanger

func WithClock

func WithClock(now func() time.Time) Opt

WithClock is the time, such as in tests

func WithHook

func WithHook(hook Hook) Opt

WithHook allows, or refuses, an identity with the hook, before it's exchanged

func WithTTL

func WithTTL(ttl time.Duration) Opt

WithTTL is how long a session lasts

func WithUsers

func WithUsers(users UserStore) Opt

WithUsers says who an identity is, and their scopes, with the store

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

Jump to

Keyboard shortcuts

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