Documentation ¶
Index ¶
- Constants
- Variables
- type ClientStore
- type ClientStoreItem
- type ClientStoreOption
- type LogLevel
- type Logger
- type NoopLogger
- type TokenStore
- func (s *TokenStore) Close(ctx context.Context)
- func (s *TokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error
- func (s *TokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)
- func (s *TokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)
- func (s *TokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)
- func (s *TokenStore) InitCleanup(ctx context.Context)
- func (s *TokenStore) InitTable(ctx context.Context) error
- func (s *TokenStore) RemoveByAccess(ctx context.Context, access string) error
- func (s *TokenStore) RemoveByCode(ctx context.Context, code string) error
- func (s *TokenStore) RemoveByRefresh(ctx context.Context, refresh string) error
- type TokenStoreItem
- type TokenStoreOption
Constants ¶
const ( LogLevelDebug = LogLevel("DEBUG") // debug level LogLevelInfo = LogLevel("INFO") // info level LogLevelWarn = LogLevel("WARN") // warn level LogLevelError = LogLevel("ERROR") // error level )
const (
// DefaultClientStoreTable is the default collection for storing clients.
DefaultClientStoreTable = "oauth2_clients"
)
const ( // DefaultTokenStoreTable is the default collection for storing tokens. DefaultTokenStoreTable = "oauth2_tokens" // nolint: gosec )
Variables ¶
var ( // ErrNoTable is returned when no table was provided. ErrNoTable = fmt.Errorf("no table provided") // ErrNoConnPool is returned when no database was provided. ErrNoConnPool = fmt.Errorf("no connection pool provided") // ErrNoLogger is returned when no logger was provided. ErrNoLogger = fmt.Errorf("no logger provided") )
Functions ¶
This section is empty.
Types ¶
type ClientStore ¶
type ClientStore struct {
// contains filtered or unexported fields
}
ClientStore is a data struct that stores oauth2 client information.
func NewClientStore ¶
func NewClientStore(opts ...ClientStoreOption) (*ClientStore, error)
NewClientStore creates a new ClientStore.
func (*ClientStore) Create ¶
func (s *ClientStore) Create(info oauth2.ClientInfo) error
Create creates a new client in the store.
type ClientStoreItem ¶
type ClientStoreItem struct { ID string `db:"id"` Secret string `db:"secret"` Domain string `db:"domain"` Data []byte `db:"data"` CreatedAt time.Time `db:"created_at"` }
ClientStoreItem data item
type ClientStoreOption ¶
type ClientStoreOption func(*ClientStore) error
ClientStoreOption is a function that configures the ClientStore.
func WithClientStoreConnPool ¶
func WithClientStoreConnPool(pool *pgxpool.Pool) ClientStoreOption
WithClientStoreConnPool configures the connection pool.
func WithClientStoreLogger ¶
func WithClientStoreLogger(logger Logger) ClientStoreOption
WithClientStoreLogger configures the logger.
func WithClientStoreTable ¶
func WithClientStoreTable(table string) ClientStoreOption
WithClientStoreTable configures the auth token table.
type Logger ¶
type Logger interface { // Log logs a message. Log(ctx context.Context, level LogLevel, msg string, args ...any) }
Logger wraps a logger to log messages.
type TokenStore ¶
type TokenStore struct {
// contains filtered or unexported fields
}
TokenStore is a data struct that stores oauth2 token information.
func NewTokenStore ¶
func NewTokenStore(opts ...TokenStoreOption) (*TokenStore, error)
NewTokenStore creates a new TokenStore.
func (*TokenStore) Close ¶
func (s *TokenStore) Close(ctx context.Context)
Close closes the store and releases any resources.
func (*TokenStore) Create ¶
func (s *TokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error
Create creates a new token in the store.
func (*TokenStore) GetByAccess ¶
func (s *TokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)
GetByAccess returns the token by its access token.
func (*TokenStore) GetByCode ¶
func (s *TokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)
GetByCode returns the token by its authorization code.
func (*TokenStore) GetByRefresh ¶
func (s *TokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)
GetByRefresh returns the token by its refresh token.
func (*TokenStore) InitCleanup ¶
func (s *TokenStore) InitCleanup(ctx context.Context)
InitCleanup initializes the cleanup process.
func (*TokenStore) InitTable ¶
func (s *TokenStore) InitTable(ctx context.Context) error
InitTable initializes the token store table if it does not exist and creates the indexes.
func (*TokenStore) RemoveByAccess ¶
func (s *TokenStore) RemoveByAccess(ctx context.Context, access string) error
func (*TokenStore) RemoveByCode ¶
func (s *TokenStore) RemoveByCode(ctx context.Context, code string) error
RemoveByCode deletes the token by its authorization code.
func (*TokenStore) RemoveByRefresh ¶
func (s *TokenStore) RemoveByRefresh(ctx context.Context, refresh string) error
type TokenStoreItem ¶
type TokenStoreItem struct { ID int64 `db:"id"` Code string `db:"code"` Access string `db:"access_token"` Refresh string `db:"refresh_token"` Data []byte `db:"data"` CreatedAt time.Time `db:"created_at"` ExpiresAt time.Time `db:"expires_at"` }
TokenStoreItem data item
type TokenStoreOption ¶
type TokenStoreOption func(*TokenStore) error
TokenStoreOption is a function that configures the TokenStore.
func WithTokenStoreCleanupInterval ¶
func WithTokenStoreCleanupInterval(interval time.Duration) TokenStoreOption
WithTokenStoreCleanupInterval configures the cleanup interval.
func WithTokenStoreConnPool ¶
func WithTokenStoreConnPool(pool *pgxpool.Pool) TokenStoreOption
WithTokenStoreConnPool configures the connection pool.
func WithTokenStoreLogger ¶
func WithTokenStoreLogger(logger Logger) TokenStoreOption
WithTokenStoreLogger configures the logger.
func WithTokenStoreTable ¶
func WithTokenStoreTable(table string) TokenStoreOption
WithTokenStoreTable configures the auth token table.