Help us shape the future of Go! Take the 2026 Go Developer Survey

store

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Overview

Package store defines simple token and client-configuration stores used by the authorization helpers in the parent `auth` package.

It currently ships with an in-memory implementation that is sufficient for most CLI or unit-test scenarios but can be swapped for a persistent backend if required.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigIssuer added in v0.20.0

func ConfigIssuer(client *oauth2.Config) string

ConfigIssuer derives the issuer key for a client config from its AuthURL, using the same derivation as WithClientConfig. The result is normalized (whitespace and trailing slashes trimmed) so that arbitrary injected Store implementations — which may not normalize keys themselves — receive the same canonical issuer key that lookups use.

func InstallClientConfig added in v0.20.0

func InstallClientConfig(s Store, client *oauth2.Config) error

InstallClientConfig registers a client config in any Store implementation under the normalized issuer derived from its AuthURL. It allows loaded OAuth client configurations to be retained when a caller injects its own Store instead of using the default in-memory store.

Types

type FileStore added in v0.7.4

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

FileStore persists tokens to a JSON file, while delegating other lookups to an in-memory store. It is a lightweight way to survive process restarts in CLI or single-host services.

func (*FileStore) AddAuthorizationServerMetadata added in v0.7.4

func (f *FileStore) AddAuthorizationServerMetadata(metadata *meta.AuthorizationServerMetadata) error

func (*FileStore) AddClientConfig added in v0.7.4

func (f *FileStore) AddClientConfig(issuer string, client *oauth2.Config) error

func (*FileStore) AddIssuerPublicKeys added in v0.7.4

func (f *FileStore) AddIssuerPublicKeys(issuer string, keys map[string]crypto.PublicKey) error

func (*FileStore) AddToken added in v0.7.4

func (f *FileStore) AddToken(key TokenKey, token *oauth2.Token) error

func (*FileStore) LookupAuthorizationServerMetadata added in v0.7.4

func (f *FileStore) LookupAuthorizationServerMetadata(issuer string) (*meta.AuthorizationServerMetadata, bool)

func (*FileStore) LookupClientConfig added in v0.7.4

func (f *FileStore) LookupClientConfig(issuer string) (*oauth2.Config, bool)

func (*FileStore) LookupIssuerPublicKeys added in v0.7.4

func (f *FileStore) LookupIssuerPublicKeys(issuer string) (map[string]crypto.PublicKey, bool)

func (*FileStore) LookupToken added in v0.7.4

func (f *FileStore) LookupToken(key TokenKey) (*oauth2.Token, bool)

type MemoryStoreOption

type MemoryStoreOption func(*memoryStore)

func WithClientConfig

func WithClientConfig(client *oauth2.Config) MemoryStoreOption

type Store

type Store interface {
	LookupClientConfig(issuer string) (*oauth2.Config, bool)
	AddClientConfig(issuer string, client *oauth2.Config) error
	AddAuthorizationServerMetadata(metadata *meta.AuthorizationServerMetadata) error
	LookupAuthorizationServerMetadata(issuer string) (*meta.AuthorizationServerMetadata, bool)
	AddIssuerPublicKeys(issuer string, keys map[string]crypto.PublicKey) error
	LookupIssuerPublicKeys(issuer string) (map[string]crypto.PublicKey, bool)
	AddToken(key TokenKey, token *oauth2.Token) error
	LookupToken(key TokenKey) (*oauth2.Token, bool)
}

Store is a pluggable persistence layer for tokens & client IDs. The in‑memory default is fine for CLI tools; swap with Redis/SQL for fleets.

func NewFileStore added in v0.7.4

func NewFileStore(path string, options ...MemoryStoreOption) Store

NewFileStore creates a Store that persists tokens at the given path. Client configs and metadata are kept in-memory (they can be rediscovered).

func NewMemoryStore

func NewMemoryStore(options ...MemoryStoreOption) Store

type TokenKey

type TokenKey struct {
	Issuer string
	Scopes string
}

Jump to

Keyboard shortcuts

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