Documentation
¶
Index ¶
- Variables
- func HashToken(token string) string
- type MemoryTokenStore
- func (s *MemoryTokenStore) Clear(_ context.Context) error
- func (s *MemoryTokenStore) Close() error
- func (s *MemoryTokenStore) Count(_ context.Context) int
- func (s *MemoryTokenStore) Delete(_ context.Context, token string) error
- func (s *MemoryTokenStore) DeleteExpired(_ context.Context) error
- func (s *MemoryTokenStore) Get(_ context.Context, token string) (*TokenEntry, error)
- func (s *MemoryTokenStore) Set(_ context.Context, token *TokenEntry) error
- type TokenCache
- type TokenCacheEntry
- type TokenEntry
- type TokenStore
Constants ¶
This section is empty.
Variables ¶
var ErrTokenNotFound = fmt.Errorf("token not found")
Functions ¶
Types ¶
type MemoryTokenStore ¶
type MemoryTokenStore struct {
// contains filtered or unexported fields
}
MemoryTokenStore implements TokenStore using ttlcache.
func (*MemoryTokenStore) Clear ¶
func (s *MemoryTokenStore) Clear(_ context.Context) error
Clear removes all tokens from the cache.
func (*MemoryTokenStore) Close ¶
func (s *MemoryTokenStore) Close() error
Close stops the cleanup goroutine.
func (*MemoryTokenStore) Count ¶
func (s *MemoryTokenStore) Count(_ context.Context) int
Count counts the number of tokens in the cache.
func (*MemoryTokenStore) Delete ¶
func (s *MemoryTokenStore) Delete(_ context.Context, token string) error
Delete removes a token from the cache.
func (*MemoryTokenStore) DeleteExpired ¶
func (s *MemoryTokenStore) DeleteExpired(_ context.Context) error
DeleteExpired removes all expired tokens from the cache.
func (*MemoryTokenStore) Get ¶
func (s *MemoryTokenStore) Get(_ context.Context, token string) (*TokenEntry, error)
Get implements TokenStore.Get.
func (*MemoryTokenStore) Set ¶
func (s *MemoryTokenStore) Set(_ context.Context, token *TokenEntry) error
Set implements TokenStore.Set.
type TokenCache ¶
type TokenCache struct {
// contains filtered or unexported fields
}
TokenCache provides thread-safe caching for tokens with TTL
func NewTokenCache ¶
func NewTokenCache(cleanupInterval time.Duration) *TokenCache
NewTokenCache creates a new token cache with the specified cleanup interval
func (*TokenCache) Delete ¶
func (tc *TokenCache) Delete(ctx context.Context, tokenString string)
Delete removes a token from the cache
func (*TokenCache) Get ¶
func (tc *TokenCache) Get(ctx context.Context, tokenString string) (*TokenCacheEntry, bool)
Get retrieves a token and its claims from the cache
type TokenCacheEntry ¶
TokenCacheEntry represents a cached token with its metadata
type TokenEntry ¶
type TokenEntry struct { ID string `redis:"id"` // Unique token identifier TokenType string `redis:"tokenType"` // "access_token" or "refresh_token" TokenValue string `redis:"tokenValue"` // The actual token string ClientID string `redis:"clientId"` // Client that requested the token UserID string `redis:"userId"` // User who authorized the token Scope string `redis:"scope"` // Authorized scopes ExpiresAt time.Time `redis:"expiresAt"` // Expiration timestamp IsRevoked bool `redis:"isRevoked"` // Whether token is revoked CreatedAt time.Time `redis:"createdAt"` // Creation timestamp LastUsedAt time.Time `redis:"lastUsedAt"` // Last usage timestamp Roles []string `redis:"roles,omitempty"` // New field }
TokenEntry represents a cached token entry
type TokenStore ¶
type TokenStore interface { // Set stores a token with its claims and expiry time Set(ctx context.Context, token *TokenEntry) error // Get retrieves a token entry from the cache Get(ctx context.Context, token string) (*TokenEntry, error) // Delete removes a token from the cache Delete(ctx context.Context, token string) error // DeleteExpired removes all expired tokens from the cache DeleteExpired(ctx context.Context) error // Clear removes all tokens from the cache Clear(ctx context.Context) error // Count returns the number of tokens in the cache Count(ctx context.Context) int }
TokenStore defines the interface for token caching implementations
func NewMemoryTokenStore ¶
func NewMemoryTokenStore(cleanupInterval time.Duration) TokenStore
NewMemoryTokenStore creates a new in-memory token store with automatic cleanup.