Documentation
¶
Index ¶
- Constants
- Variables
- func ActorFromContext(ctx context.Context) (admin.Actor, bool)
- func CSRFMiddleware(next http.Handler) http.Handler
- func ContextWithActor(ctx context.Context, actor admin.Actor) context.Context
- func HashPassword(password string, config PasswordConfig) (string, error)
- func IssueCSRF(w http.ResponseWriter, secure bool) (string, error)
- func VerifyPassword(password, encoded string) (bool, error)
- type APIKey
- type APIKeyManager
- type CacheSessionStore
- type CreateAPIKeyInput
- type MemorySessionStore
- type OAuthIdentity
- type OAuthProvider
- type OAuthState
- type OAuthStateManager
- type PGAPIKeys
- func (s *PGAPIKeys) Authenticate(ctx context.Context, rawKey string) (admin.Actor, APIKey, bool, error)
- func (s *PGAPIKeys) Create(ctx context.Context, input CreateAPIKeyInput) (APIKey, string, error)
- func (s *PGAPIKeys) List(ctx context.Context, actor admin.Actor) ([]APIKey, error)
- func (s *PGAPIKeys) Migrate(ctx context.Context) error
- func (s *PGAPIKeys) Revoke(ctx context.Context, id string, actor admin.Actor) error
- type PGSessionStore
- func (s *PGSessionStore) Cleanup(ctx context.Context) (int64, error)
- func (s *PGSessionStore) Create(ctx context.Context, actor admin.Actor, ttl time.Duration) (Session, error)
- func (s *PGSessionStore) Delete(ctx context.Context, id string) error
- func (s *PGSessionStore) Get(ctx context.Context, id string) (Session, error)
- func (s *PGSessionStore) Migrate(ctx context.Context) error
- type PasswordConfig
- type RateLimiter
- type Session
- type SessionManager
- type SessionStore
Constants ¶
const SessionTableDDL = `` /* 308-byte string literal not displayed */
SessionTableDDL is the CREATE TABLE statement for the sessions table. Call PGSessionStore.Migrate to execute it.
Variables ¶
var ErrAPIKeyNotFound = errors.New("api key not found")
var ErrInvalidHash = errors.New("invalid password hash")
var ErrOAuthStateInvalid = errors.New("invalid oauth state")
var ErrSessionNotFound = errors.New("session not found")
Functions ¶
func ContextWithActor ¶ added in v0.6.0
func HashPassword ¶
func HashPassword(password string, config PasswordConfig) (string, error)
func VerifyPassword ¶
Types ¶
type APIKey ¶ added in v0.6.0
type APIKey struct {
ID string `json:"id"`
Name string `json:"name"`
Prefix string `json:"prefix"`
Scopes []string `json:"scopes"`
Actor admin.Actor `json:"actor"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
RevokedAt *time.Time `json:"revoked_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
type APIKeyManager ¶ added in v0.6.0
type APIKeyManager interface {
Authenticate(ctx context.Context, rawKey string) (admin.Actor, APIKey, bool, error)
Create(ctx context.Context, input CreateAPIKeyInput) (APIKey, string, error)
List(ctx context.Context, actor admin.Actor) ([]APIKey, error)
Revoke(ctx context.Context, id string, actor admin.Actor) error
}
type CacheSessionStore ¶ added in v0.4.0
CacheSessionStore stores sessions in any cache.Cache implementation. Use it with Redis, Memcached, Dragonfly, KeyDB, or an existing app cache.
func NewCacheSessionStore ¶ added in v0.4.0
func NewCacheSessionStore(c cache.Cache) *CacheSessionStore
type CreateAPIKeyInput ¶ added in v0.6.0
type MemorySessionStore ¶
type MemorySessionStore struct {
// contains filtered or unexported fields
}
func NewMemorySessionStore ¶
func NewMemorySessionStore() *MemorySessionStore
type OAuthIdentity ¶ added in v0.6.0
type OAuthProvider ¶ added in v0.6.0
type OAuthProvider struct {
Name string
ClientID string
ClientSecret string
AuthURL string
TokenURL string
UserInfoURL string
Scopes []string
UserIDField string
UserEmailField string
UserNameField string
}
func GoogleOAuthProvider ¶ added in v0.6.0
func GoogleOAuthProvider(clientID, clientSecret string) OAuthProvider
func (OAuthProvider) AuthorizationURL ¶ added in v0.6.0
func (p OAuthProvider) AuthorizationURL(redirectURI, state string) string
func (OAuthProvider) Exchange ¶ added in v0.6.0
func (p OAuthProvider) Exchange(ctx context.Context, code, redirectURI string) (OAuthIdentity, error)
type OAuthState ¶ added in v0.6.0
type OAuthStateManager ¶ added in v0.6.0
func (OAuthStateManager) Begin ¶ added in v0.6.0
func (m OAuthStateManager) Begin(w http.ResponseWriter, state OAuthState) (string, error)
func (OAuthStateManager) Clear ¶ added in v0.6.0
func (m OAuthStateManager) Clear(w http.ResponseWriter)
func (OAuthStateManager) Verify ¶ added in v0.6.0
func (m OAuthStateManager) Verify(r *http.Request, state string) (OAuthState, error)
type PGAPIKeys ¶ added in v0.6.0
type PGAPIKeys struct {
// contains filtered or unexported fields
}
func NewPGAPIKeys ¶ added in v0.6.0
func (*PGAPIKeys) Authenticate ¶ added in v0.6.0
type PGSessionStore ¶
type PGSessionStore struct {
// contains filtered or unexported fields
}
PGSessionStore is a PostgreSQL-backed SessionStore. Use NewPGSessionStore to construct it, then call Migrate once at startup.
func NewPGSessionStore ¶
func NewPGSessionStore(pool *pgxpool.Pool) *PGSessionStore
NewPGSessionStore creates a PGSessionStore backed by the supplied pool.
func (*PGSessionStore) Cleanup ¶
func (s *PGSessionStore) Cleanup(ctx context.Context) (int64, error)
Cleanup deletes all expired sessions and returns the number of rows removed. Schedule this periodically (e.g. every hour) to keep the table small.
func (*PGSessionStore) Create ¶
func (s *PGSessionStore) Create(ctx context.Context, actor admin.Actor, ttl time.Duration) (Session, error)
Create inserts a new session for actor with the given TTL and returns it.
func (*PGSessionStore) Delete ¶
func (s *PGSessionStore) Delete(ctx context.Context, id string) error
Delete removes a session. It is not an error if the session does not exist.
type PasswordConfig ¶
type PasswordConfig struct {
Memory uint32
Iterations uint32
Parallelism uint8
SaltLength uint32
KeyLength uint32
}
func DefaultPasswordConfig ¶
func DefaultPasswordConfig() PasswordConfig
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
func NewRateLimiter ¶
func NewRateLimiter(limit int, window time.Duration) *RateLimiter
func (*RateLimiter) Allow ¶
func (l *RateLimiter) Allow(key string) bool
func (*RateLimiter) Middleware ¶
func (l *RateLimiter) Middleware(next http.Handler) http.Handler
type SessionManager ¶
type SessionManager struct {
Store SessionStore
CookieName string
TTL time.Duration
Secure bool
SameSite http.SameSite
}
func NewSessionManager ¶
func NewSessionManager(store SessionStore) *SessionManager
func (*SessionManager) End ¶
func (m *SessionManager) End(ctx context.Context, w http.ResponseWriter, r *http.Request) error
func (*SessionManager) Middleware ¶
func (m *SessionManager) Middleware(next http.Handler) http.Handler