oidcProviderStore

package
v0.2.70 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InteractionPurposeConsent = "consent"
	InteractionPurposeLogin   = "login"
)

Variables

View Source
var ErrInteractionInvalid = errors.New("OIDC interaction is missing, expired, used, or belongs to another user")

Functions

func Models

func Models() []any

Models returns every schema object required by Store.

Types

type AuthorizationCodeEntity

type AuthorizationCodeEntity struct {
	Hash                string    `gorm:"primaryKey;column:code_hash;type:varchar(64);not null"`
	GrantID             string    `gorm:"column:grant_id;type:varchar(64);not null;default:'';index:idx_oidc_codes_grant"`
	UserID              string    `gorm:"column:user_id;type:varchar(255);not null;index:idx_oidc_codes_grant_owner,priority:1"`
	ClientID            string    `gorm:"column:client_id;type:varchar(255);not null;index:idx_oidc_codes_grant_owner,priority:2"`
	RedirectURI         string    `gorm:"column:redirect_uri;type:text;not null"`
	Scopes              []string  `gorm:"column:scopes;type:text;not null;serializer:json"`
	Nonce               string    `gorm:"column:nonce;type:varchar(255);not null;default:''"`
	CodeChallenge       string    `gorm:"column:code_challenge;type:varchar(128);not null;default:''"`
	CodeChallengeMethod string    `gorm:"column:code_challenge_method;type:varchar(16);not null;default:''"`
	ExpiresAt           time.Time `gorm:"column:expires_at;not null;index:idx_oidc_codes_expiry"`
	AuthTime            time.Time `gorm:"column:auth_time;not null"`
	Used                bool      `gorm:"column:used;not null;default:false;index:idx_oidc_codes_grant_owner,priority:3"`
	CreatedAt           time.Time
}

func (AuthorizationCodeEntity) TableName

func (AuthorizationCodeEntity) TableName() string

type ClientEntity

type ClientEntity struct {
	ID                      string   `gorm:"primaryKey;column:client_id;type:varchar(255);not null"`
	Name                    string   `gorm:"column:name;type:varchar(255);not null;default:''"`
	SecretHash              string   `gorm:"column:secret_hash;type:varchar(64);not null;default:''"`
	RedirectURIs            []string `gorm:"column:redirect_uris;type:text;not null;serializer:json"`
	Scopes                  []string `gorm:"column:scopes;type:text;not null;serializer:json"`
	GrantTypes              []string `gorm:"column:grant_types;type:text;not null;serializer:json"`
	TokenEndpointAuthMethod string   `gorm:"column:token_endpoint_auth_method;type:varchar(32);not null"`
	RequirePKCE             bool     `gorm:"column:require_pkce;not null;default:false"`
	Public                  bool     `gorm:"column:is_public;not null;default:false"`
	Enabled                 bool     `gorm:"column:enabled;not null;default:true;index:idx_oidc_clients_enabled"`
	CreatedAt               time.Time
	UpdatedAt               time.Time
}

func (ClientEntity) TableName

func (ClientEntity) TableName() string

type ConsentEntity

type ConsentEntity struct {
	UserID    string   `gorm:"primaryKey;column:user_id;type:varchar(255);not null"`
	ClientID  string   `gorm:"primaryKey;column:client_id;type:varchar(255);not null;index:idx_oidc_consents_client"`
	Scopes    []string `gorm:"column:scopes;type:text;not null;serializer:json"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (ConsentEntity) TableName

func (ConsentEntity) TableName() string

type InteractionEntity

type InteractionEntity struct {
	Hash           string     `gorm:"primaryKey;column:interaction_hash;type:varchar(64);not null"`
	RequestJSON    []byte     `gorm:"column:request_json;type:blob;not null"`
	Purpose        string     `gorm:"column:purpose;type:varchar(16);not null;default:consent;index:idx_oidc_interactions_purpose"`
	UserID         string     `gorm:"column:user_id;type:varchar(255);not null;index:idx_oidc_interactions_user"`
	AuthTime       time.Time  `gorm:"column:auth_time;not null"`
	AuthFresh      bool       `gorm:"column:auth_fresh;not null;default:false"`
	PreviousAuthID string     `gorm:"column:previous_auth_id;type:varchar(64);not null;default:''"`
	StartedAt      time.Time  `gorm:"column:started_at;not null;default:CURRENT_TIMESTAMP"`
	ExpiresAt      time.Time  `gorm:"column:expires_at;not null;index:idx_oidc_interactions_expiry"`
	Used           bool       `gorm:"column:used;not null;default:false"`
	UsedAt         *time.Time `gorm:"column:used_at"`
	CreatedAt      time.Time
}

InteractionEntity is a short-lived, single-use browser interaction. Hash is the digest of the random handle shown to the browser; the handle itself is never persisted. RequestJSON is the server-validated authorization request.

func (InteractionEntity) TableName

func (InteractionEntity) TableName() string

type SigningKeyEntity

type SigningKeyEntity struct {
	ID                  uint8  `gorm:"primaryKey;column:id;not null"`
	KID                 string `gorm:"column:kid;type:varchar(64);not null;uniqueIndex"`
	EncryptedPrivateKey []byte `gorm:"column:encrypted_private_key;type:blob;not null"`
	CreatedAt           time.Time
	UpdatedAt           time.Time
}

SigningKeyEntity stores the single active OIDC signing key. The private key is encrypted by the runtime service before it crosses this persistence boundary.

func (SigningKeyEntity) TableName

func (SigningKeyEntity) TableName() string

type SigningKeyHistoryEntity

type SigningKeyHistoryEntity struct {
	KID       string    `gorm:"primaryKey;column:kid;type:varchar(64);not null"`
	PublicKey []byte    `gorm:"column:public_key;type:blob;not null"`
	RetireAt  time.Time `gorm:"column:retire_at;not null;index:idx_oidc_signing_key_history_retire"`
	CreatedAt time.Time
}

func (SigningKeyHistoryEntity) TableName

func (SigningKeyHistoryEntity) TableName() string

type Store

type Store struct {
	// contains filtered or unexported fields
}

func New

func New(db *gorm.DB) (*Store, error)

func (*Store) ConsumeInteraction

func (s *Store) ConsumeInteraction(ctx context.Context, hash, userID string, now time.Time) (*InteractionEntity, error)

ConsumeInteraction atomically marks one live, user-bound interaction used and returns its trusted request snapshot. Exactly one concurrent caller can succeed on SQLite, MySQL, or any GORM database with transactional updates.

func (*Store) ConsumeLoginInteraction

func (s *Store) ConsumeLoginInteraction(ctx context.Context, hash, authID string, authTime, now time.Time) (*InteractionEntity, error)

ConsumeLoginInteraction atomically marks a live login interaction used only after a distinct authentication ceremony completed after it began.

func (*Store) CreateClient

func (s *Store) CreateClient(ctx context.Context, client *core.Client) error

CreateClient inserts a registration without overwriting an existing client. Administrative creation uses this so an ID collision cannot replace an existing client's credentials or redirect URI allowlist.

func (*Store) CreateInteraction

func (s *Store) CreateInteraction(ctx context.Context, interaction *InteractionEntity) error

func (*Store) CreateSigningKeyIfAbsent

func (s *Store) CreateSigningKeyIfAbsent(ctx context.Context, entity *SigningKeyEntity) (created bool, err error)

CreateSigningKeyIfAbsent atomically installs the first signing key. A concurrent process that lost the insert race receives created=false and must reload the winner.

func (*Store) ExchangeAuthorizationCode

func (s *Store) ExchangeAuthorizationCode(ctx context.Context, exchange core.AuthorizationCodeExchange) error

func (*Store) GetAccessToken

func (s *Store) GetAccessToken(ctx context.Context, hash string) (*core.Token, error)

func (*Store) GetAuthorizationCode

func (s *Store) GetAuthorizationCode(ctx context.Context, hash string) (*core.AuthorizationCode, error)

func (*Store) GetClient

func (s *Store) GetClient(ctx context.Context, id string) (*core.Client, error)

func (*Store) GetConsent

func (s *Store) GetConsent(ctx context.Context, userID, clientID string) (*core.Consent, error)

func (*Store) GetInteraction

func (s *Store) GetInteraction(ctx context.Context, hash, userID string, now time.Time) (*InteractionEntity, error)

GetInteraction returns only a live interaction belonging to userID.

func (*Store) GetRefreshToken

func (s *Store) GetRefreshToken(ctx context.Context, hash string) (*core.Token, error)

func (*Store) GetSigningKey

func (s *Store) GetSigningKey(ctx context.Context) (*SigningKeyEntity, error)

GetSigningKey returns the active singleton signing-key record.

func (*Store) ListClients

func (s *Store) ListClients(ctx context.Context) ([]core.Client, error)

func (*Store) ListSigningKeyHistory

func (s *Store) ListSigningKeyHistory(ctx context.Context) ([]SigningKeyHistoryEntity, error)

func (*Store) ListUserGrants

func (s *Store) ListUserGrants(ctx context.Context, userID string) ([]UserGrant, error)

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

func (*Store) Purge

func (s *Store) Purge(ctx context.Context, request core.PurgeRequest) (core.PurgeResult, error)

func (*Store) PurgeInteractions

func (s *Store) PurgeInteractions(ctx context.Context, now time.Time) (int64, error)

func (*Store) PurgeSigningKeyHistory

func (s *Store) PurgeSigningKeyHistory(ctx context.Context, now time.Time) (int64, error)

func (*Store) RevokeAuthorizationCodeGrant

func (s *Store) RevokeAuthorizationCodeGrant(ctx context.Context, codeHash string, now time.Time) error

func (*Store) RevokeGrant

func (s *Store) RevokeGrant(ctx context.Context, userID, clientID string, now time.Time) error

func (*Store) RevokeToken

func (s *Store) RevokeToken(ctx context.Context, hash, clientID string, now time.Time) error

func (*Store) RevokeTokenFamily

func (s *Store) RevokeTokenFamily(ctx context.Context, family string, now time.Time) error

func (*Store) RotateRefreshToken

func (s *Store) RotateRefreshToken(ctx context.Context, rotation core.RefreshTokenRotation) error

func (*Store) RotateSigningKey

func (s *Store) RotateSigningKey(ctx context.Context, previousKID string, next *SigningKeyEntity, history *SigningKeyHistoryEntity) error

func (*Store) SaveAuthorizationCode

func (s *Store) SaveAuthorizationCode(ctx context.Context, code *core.AuthorizationCode) error

func (*Store) SaveClient

func (s *Store) SaveClient(ctx context.Context, client *core.Client) error

func (*Store) SaveConsent

func (s *Store) SaveConsent(ctx context.Context, consent *core.Consent) error

type TokenEntity

type TokenEntity struct {
	Hash            string     `gorm:"primaryKey;column:token_hash;type:varchar(64);not null"`
	Type            string     `gorm:"column:token_type;type:varchar(8);not null;index:idx_oidc_tokens_type_expiry,priority:1"`
	GrantID         string     `gorm:"column:grant_id;type:varchar(64);not null;default:'';index:idx_oidc_tokens_grant"`
	FamilyID        string     `gorm:"column:family_id;type:varchar(64);not null;default:'';index:idx_oidc_tokens_family"`
	UserID          string     `gorm:"column:user_id;type:varchar(255);not null;index:idx_oidc_tokens_owner,priority:1"`
	ClientID        string     `gorm:"column:client_id;type:varchar(255);not null;index:idx_oidc_tokens_owner,priority:2"`
	Scopes          []string   `gorm:"column:scopes;type:text;not null;serializer:json"`
	ExpiresAt       time.Time  `gorm:"column:expires_at;not null;index:idx_oidc_tokens_type_expiry,priority:2"`
	FamilyExpiresAt *time.Time `gorm:"column:family_expires_at;index:idx_oidc_tokens_family_expiry"`
	RevokedAt       *time.Time `gorm:"column:revoked_at;index:idx_oidc_tokens_revoked"`
	AuthTime        time.Time  `gorm:"column:auth_time;not null"`
	CreatedAt       time.Time
}

func (TokenEntity) TableName

func (TokenEntity) TableName() string

type UserGrant

type UserGrant struct {
	ClientID  string
	Name      string
	Scopes    []string
	GrantedAt time.Time
	Enabled   bool
}

Jump to

Keyboard shortcuts

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