Documentation
¶
Index ¶
- Constants
- func GenerateRandomString(length int) (string, error)
- type Client
- func (c *Client) GetAudience() fosite.Arguments
- func (c *Client) GetGrantTypes() fosite.Arguments
- func (c *Client) GetHashedSecret() []byte
- func (c *Client) GetID() string
- func (c *Client) GetRedirectURIs() []string
- func (c *Client) GetResponseTypes() fosite.Arguments
- func (c *Client) GetScopes() fosite.Arguments
- func (c *Client) GetTokenEndpointAuthMethod() string
- func (c *Client) IsPublic() bool
- type ClientService
- func (s *ClientService) CreateClient(ctx context.Context, name, description, redirectURI string, scopes []string) (*ClientWithSecret, error)
- func (s *ClientService) DeleteClient(id string) error
- func (s *ClientService) GetClient(ctx context.Context, id string) (*Client, error)
- func (s *ClientService) ListClients(ctx context.Context) ([]*Client, error)
- func (s *ClientService) RotateClientSecret(ctx context.Context, clientID string) (*ClientWithSecret, error)
- func (s *ClientService) UpdateClient(ctx context.Context, clientID string, updates map[string]any) (*Client, error)
- type ClientWithSecret
- type Server
- func (s *Server) HandleAuthorizeRequest(writer http.ResponseWriter, request *http.Request)
- func (s *Server) HandleTokenRequest(writer http.ResponseWriter, request *http.Request)
- func (s *Server) Provider() fosite.OAuth2Provider
- func (s *Server) Storage() *Storage
- func (s *Server) ValidateAccessToken(ctx context.Context, token string) (string, []string, error)
- type Storage
- func (s *Storage) Authenticate(_ context.Context, _ string) error
- func (s *Storage) ClientAssertionJWTValid(_ context.Context, _ string) error
- func (s *Storage) CreateAccessTokenSession(_ context.Context, signature string, req fosite.Requester) error
- func (s *Storage) CreateAuthorizeCodeSession(ctx context.Context, code string, req fosite.Requester) error
- func (s *Storage) CreatePKCERequestSession(_ context.Context, signature string, req fosite.Requester) error
- func (s *Storage) CreateRefreshTokenSession(_ context.Context, signature string, accessSignature string, ...) error
- func (s *Storage) DeleteAccessTokenSession(_ context.Context, signature string) error
- func (s *Storage) DeletePKCERequestSession(_ context.Context, signature string) error
- func (s *Storage) DeleteRefreshTokenSession(_ context.Context, signature string) error
- func (s *Storage) GetAccessTokenSession(ctx context.Context, signature string, session fosite.Session) (fosite.Requester, error)
- func (s *Storage) GetAuthorizeCodeSession(ctx context.Context, code string, session fosite.Session) (fosite.Requester, error)
- func (s *Storage) GetClient(_ context.Context, id string) (fosite.Client, error)
- func (s *Storage) GetPKCERequestSession(ctx context.Context, signature string, session fosite.Session) (fosite.Requester, error)
- func (s *Storage) GetRefreshTokenSession(ctx context.Context, signature string, session fosite.Session) (fosite.Requester, error)
- func (s *Storage) InvalidateAuthorizeCodeSession(_ context.Context, code string) error
- func (s *Storage) RevokeAccessToken(_ context.Context, requestID string) error
- func (s *Storage) RevokeRefreshToken(_ context.Context, requestID string) error
- func (s *Storage) RevokeRefreshTokenMaybeGracePeriod(ctx context.Context, requestID string, _ string) error
- func (s *Storage) RotateRefreshToken(_ context.Context, _ string, refreshTokenSignature string) error
- func (s *Storage) SetClientAssertionJWT(_ context.Context, _ string, _ time.Time) error
- type StorageAdapter
- func (s *StorageAdapter) Delete(key string) error
- func (s *StorageAdapter) Get(key string, value any) error
- func (s *StorageAdapter) GetWithContext(ctx context.Context, key string, value any) error
- func (s *StorageAdapter) Set(key string, value any, ttl time.Duration) error
- func (s *StorageAdapter) SetWithContext(ctx context.Context, key string, value any, ttl time.Duration) error
- type StorageInterface
- type TokenClaims
- type TokenService
- type TokenServicer
Constants ¶
const JWTKeySize = 32
JWTKeySize is the key size for JWT signing (256-bit).
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomString ¶
GenerateRandomString creates a random string of the specified length.
Types ¶
type Client ¶
type Client struct {
ID string `json:"id"`
Secret []byte `json:"secret"`
Name string `json:"name"`
Description string `json:"description"`
RedirectURIs []string `json:"redirect_uris"`
GrantTypes []string `json:"grant_types"`
Scopes []string `json:"scopes"`
Audience []string `json:"audience"`
Public bool `json:"public"`
Active bool `json:"active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Client implements fosite.Client interface and serves as the unified client model.
func (*Client) GetAudience ¶
GetAudience returns the client's audience.
func (*Client) GetGrantTypes ¶
GetGrantTypes returns the allowed grant types.
func (*Client) GetHashedSecret ¶
GetHashedSecret returns the hashed client secret.
func (*Client) GetRedirectURIs ¶
GetRedirectURIs returns the client's redirect URIs.
func (*Client) GetResponseTypes ¶
GetResponseTypes returns the allowed response types.
func (*Client) GetTokenEndpointAuthMethod ¶
GetTokenEndpointAuthMethod returns the client's token endpoint authentication method.
type ClientService ¶
type ClientService struct {
// contains filtered or unexported fields
}
ClientService manages client applications.
func NewClientService ¶
func NewClientService(store *storage.Store) *ClientService
NewClientService creates a new client service.
func (*ClientService) CreateClient ¶
func (s *ClientService) CreateClient( ctx context.Context, name, description, redirectURI string, scopes []string, ) (*ClientWithSecret, error)
CreateClient registers a new client.
func (*ClientService) DeleteClient ¶
func (s *ClientService) DeleteClient(id string) error
DeleteClient removes a client.
func (*ClientService) ListClients ¶
func (s *ClientService) ListClients(ctx context.Context) ([]*Client, error)
ListClients returns all registered clients.
func (*ClientService) RotateClientSecret ¶ added in v0.3.0
func (s *ClientService) RotateClientSecret(ctx context.Context, clientID string) (*ClientWithSecret, error)
RotateClientSecret generates and sets a new secret for the client, returning it in plaintext once.
func (*ClientService) UpdateClient ¶
func (s *ClientService) UpdateClient(ctx context.Context, clientID string, updates map[string]any) (*Client, error)
UpdateClient updates a client's information.
type ClientWithSecret ¶
ClientWithSecret holds a client and its plaintext secret for API responses.
func NewClientWithDetails ¶
func NewClientWithDetails(name, description, redirectURI string, scopes []string) (*ClientWithSecret, error)
NewClientWithDetails creates a new client with auto-generated ID and secret.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps Fosite OAuth2 provider.
func (*Server) HandleAuthorizeRequest ¶
func (s *Server) HandleAuthorizeRequest(writer http.ResponseWriter, request *http.Request)
HandleAuthorizeRequest handles OAuth2 authorization requests.
func (*Server) HandleTokenRequest ¶
func (s *Server) HandleTokenRequest(writer http.ResponseWriter, request *http.Request)
HandleTokenRequest handles OAuth2 token requests.
func (*Server) Provider ¶
func (s *Server) Provider() fosite.OAuth2Provider
Provider returns the fosite OAuth2 provider.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage implements fosite.Storage interface using our storage backend.
func (*Storage) Authenticate ¶
Authenticate is required by fosite.Storage but can be no-ops for basic implementation.
func (*Storage) ClientAssertionJWTValid ¶
func (*Storage) CreateAccessTokenSession ¶
func (*Storage) CreateAuthorizeCodeSession ¶
func (*Storage) CreatePKCERequestSession ¶
func (*Storage) CreateRefreshTokenSession ¶
func (*Storage) DeleteAccessTokenSession ¶
func (*Storage) DeletePKCERequestSession ¶
func (*Storage) DeleteRefreshTokenSession ¶
func (*Storage) GetAccessTokenSession ¶
func (*Storage) GetAuthorizeCodeSession ¶
func (*Storage) GetPKCERequestSession ¶
func (*Storage) GetRefreshTokenSession ¶
func (*Storage) InvalidateAuthorizeCodeSession ¶
func (*Storage) RevokeAccessToken ¶
func (*Storage) RevokeRefreshToken ¶
func (*Storage) RevokeRefreshTokenMaybeGracePeriod ¶
func (*Storage) RotateRefreshToken ¶
type StorageAdapter ¶
type StorageAdapter struct {
// contains filtered or unexported fields
}
StorageAdapter adapts our storage.Store to work with FositeStore.
func NewStorageAdapter ¶
func NewStorageAdapter(store *storage.Store) *StorageAdapter
NewStorageAdapter creates a new storage adapter.
func (*StorageAdapter) Delete ¶
func (s *StorageAdapter) Delete(key string) error
Delete removes a value.
func (*StorageAdapter) Get ¶
func (s *StorageAdapter) Get(key string, value any) error
Get retrieves a value (StorageInterface compatibility).
func (*StorageAdapter) GetWithContext ¶
GetWithContext retrieves a value using provided context.
func (*StorageAdapter) SetWithContext ¶
func (s *StorageAdapter) SetWithContext(ctx context.Context, key string, value any, ttl time.Duration) error
SetWithContext stores a value with optional TTL using provided context.
type StorageInterface ¶
type StorageInterface interface {
Set(key string, value any, ttl time.Duration) error
Get(key string, value any) error
Delete(key string) error
}
StorageInterface defines what we need from our storage.
type TokenClaims ¶
type TokenClaims struct {
ClientID string `json:"client_id"`
UserID string `json:"user_id,omitempty"`
Scopes []string `json:"scopes"`
}
TokenClaims represents token information passed through request context.
type TokenService ¶
type TokenService struct {
// contains filtered or unexported fields
}
TokenService manages OAuth tokens.
func NewTokenService ¶
func NewTokenService(store *storage.Store) *TokenService
NewTokenService creates a new token service.
func (*TokenService) GetProviderToken ¶
GetProviderToken retrieves the current OAuth provider token.
func (*TokenService) NeedsProactiveRefresh ¶
func (s *TokenService) NeedsProactiveRefresh(ctx context.Context) bool
NeedsProactiveRefresh checks if the token should be refreshed proactively Returns true if the token expires in less than 3 days.
func (*TokenService) StoreProviderToken ¶
func (s *TokenService) StoreProviderToken( ctx context.Context, accessToken, tokenType, refreshToken string, expiresIn int, ) error
StoreProviderToken stores an OAuth token from a provider.
type TokenServicer ¶
type TokenServicer interface {
StoreProviderToken(ctx context.Context, accessToken, tokenType, refreshToken string, expiresIn int) error
GetProviderToken(ctx context.Context) (*oauth2.Token, error)
NeedsProactiveRefresh(ctx context.Context) bool
}
TokenServicer defines the interface for token management.