Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyCORSHeaders(w http.ResponseWriter, allowedMethods string)
- func CORSMiddleware(handler http.Handler) http.Handler
- func HandlePreflight(w http.ResponseWriter, r *http.Request) bool
- type AuthResponse
- type AuthorizationRule
- type ClaimRule
- type ClientRegistrationConfig
- type Config
- type Connector
- type Metadata
- type OAuthClientInformation
- type OAuthClientMetadata
- type OAuthError
- type OAuthErrorResponse
- type Plugin
- func (p *Plugin) Doc() string
- func (p *Plugin) Enrich(swag *huma.OpenAPI) *huma.OpenAPI
- func (p *Plugin) EnrichMCP(tooler plugins.MCPTooler)
- func (p *Plugin) HandleAuthorize(w http.ResponseWriter, r *http.Request)
- func (p *Plugin) HandleCallback(w http.ResponseWriter, r *http.Request)
- func (p *Plugin) HandleRegister(w http.ResponseWriter, r *http.Request)
- func (p *Plugin) HandleToken(w http.ResponseWriter, r *http.Request)
- func (p *Plugin) RegisterRoutes(mux *http.ServeMux)
- func (p *Plugin) Wrap(connector connectors.Connector) (connectors.Connector, error)
- type PluginBundle
- type RegistrationHandlerOptions
- type SimpleRateLimiter
- type TokenHandlerOptions
- type TokenRequest
Constants ¶
const ( // DefaultClientSecretExpirySeconds is the default expiry time for client secrets (30 days) DefaultClientSecretExpirySeconds int64 = 30 * 24 * 60 * 60 )
Variables ¶
var ( // ErrClientNotFound is returned when a client with the specified ID is not found ErrClientNotFound = errors.New("oauth client not found") // ErrClientSecretExpired is returned when a client's secret has expired ErrClientSecretExpired = errors.New("oauth client secret has expired") // ErrInvalidClientMetadata is returned when client metadata is invalid ErrInvalidClientMetadata = errors.New("invalid oauth client metadata") // ErrMissingRedirectURIs is returned when no redirect URIs are provided ErrMissingRedirectURIs = errors.New("redirect_uris is required") // ErrRateLimitExceeded is returned when rate limit is exceeded ErrRateLimitExceeded = errors.New("rate limit exceeded") // ErrInvalidRequest is returned when the request is malformed ErrInvalidRequest = &OAuthError{ErrorType: "invalid_request", Description: "Invalid request"} // ErrUnsupportedGrantType is returned when the grant type is not supported ErrUnsupportedGrantType = &OAuthError{ErrorType: "unsupported_grant_type", Description: "Unsupported grant type"} )
OAuth error definitions
var ErrServerError = &OAuthError{ErrorType: "server_error", Description: "Internal server error"}
Define ErrServerError if not already defined
Functions ¶
func ApplyCORSHeaders ¶ added in v0.2.9
func ApplyCORSHeaders(w http.ResponseWriter, allowedMethods string)
ApplyCORSHeaders adds the standard CORS headers to a response For handlers that are not wrapped in middleware
func CORSMiddleware ¶ added in v0.2.9
CORSMiddleware applies standard CORS headers to the response
func HandlePreflight ¶ added in v0.2.9
func HandlePreflight(w http.ResponseWriter, r *http.Request) bool
HandlePreflight checks if the request is a preflight OPTIONS request and handles it Returns true if the request was handled (caller should return immediately)
Types ¶
type AuthResponse ¶
type AuthorizationRule ¶
type AuthorizationRule struct {
// Methods defines the list of methods to which the rule applies
Methods []string `yaml:"methods"`
// AllowPublic allows public access without a token
AllowPublic bool `yaml:"allow_public"`
// RequireAllClaims determines if all ClaimRules must be true (AND)
// If false, one true rule is sufficient (OR)
RequireAllClaims bool `yaml:"require_all_claims"`
// ClaimRules list of claim validation rules
ClaimRules []ClaimRule `yaml:"claim_rules"`
}
AuthorizationRule defines an authorization rule for a method or group of methods
type ClaimRule ¶
type ClaimRule struct {
// Claim defines the path to the value in JWT or user data (e.g., "email", "groups[0]", "org.name")
Claim string `yaml:"claim"`
// Operation defines the comparison operation ("eq", "ne", "contains", "regex", "exists")
Operation string `yaml:"operation"`
// Value is the expected value for comparison
Value string `yaml:"value"`
}
ClaimRule represents a rule for checking a claim value
type ClientRegistrationConfig ¶ added in v0.2.9
type ClientRegistrationConfig struct {
// Enabled indicates whether dynamic client registration is enabled
Enabled bool `yaml:"enabled"`
// ClientSecretExpirySeconds is the number of seconds after which client secrets expire
// If 0, client secrets will not expire (not recommended)
ClientSecretExpirySeconds int64 `yaml:"client_secret_expiry_seconds"`
// RateLimitRequestsPerHour is the maximum number of registration requests per hour
// If 0, rate limiting is disabled
RateLimitRequestsPerHour float64 `yaml:"rate_limit_requests_per_hour"`
}
ClientRegistrationConfig represents configuration for dynamic client registration
type Config ¶
type Config struct {
// Provider specifies the OAuth provider ("google", "github", "auth0", "keycloak", "okta")
Provider string `yaml:"provider"`
// ProviderAuthURL specifies oauth2.Endpoint AuthURL if Provider is unknown
ProviderAuthURL string `yaml:"provider_auth_url"`
// ProviderTokenURL specifies oauth2.Endpoint TokenURL if Provider is unknown
ProviderTokenURL string `yaml:"provider_token_url"`
// ClientID is the OAuth Client ID
ClientID string `yaml:"client_id"`
// ClientSecret is the OAuth Client Secret
ClientSecret string `yaml:"client_secret"`
// RedirectURL for OAuth flow
RedirectURL string `yaml:"redirect_url"`
// IssuerURL for OAuth MCP flow
IssuerURL string `yaml:"issuer_url"`
// Scopes defines required access scopes
Scopes []string `yaml:"scopes"`
// TokenHeader defines the header name for the token (default: "Authorization")
TokenHeader string `yaml:"token_header"`
// AuthURL is the gateway's authorization endpoint path (default: "/oauth/authorize")
AuthURL string `yaml:"auth_url"`
// CallbackURL is the gateway's callback endpoint path (default: "/oauth/callback")
CallbackURL string `yaml:"callback_url"`
// TokenURL is the gateway's token endpoint path (default: "/oauth/token")
TokenURL string `yaml:"token_url"`
// RegisterURL is the gateway's client registration endpoint path (default: "/oauth/register")
RegisterURL string `yaml:"register_url"`
// UserInfoURL is the endpoint for retrieving user information (required for Auth0)
UserInfoURL string `yaml:"user_info_url"`
// IntrospectionURL is the token introspection endpoint (required for Keycloak and Okta)
IntrospectionURL string `yaml:"introspection_url"`
// AuthorizationRules defines authorization rules for methods
AuthorizationRules []AuthorizationRule `yaml:"authorization_rules"`
// ClientRegistration contains configuration for dynamic client registration
ClientRegistration ClientRegistrationConfig `yaml:"client_registration"`
// Version of MCP protocol auth
MCPProtocolVersion string `yaml:"mcp_protocol_version"`
}
Config represents OAuth plugin configuration
func (Config) GetOAuthConfig ¶
GetOAuthConfig returns oauth2.Config for the specified provider
func (*Config) WithDefaults ¶
func (c *Config) WithDefaults()
WithDefaults sets default values for the config fields
type Connector ¶
type Connector struct {
connectors.Connector
// contains filtered or unexported fields
}
type Metadata ¶ added in v0.2.9
type Metadata struct {
Issuer string `json:"issuer"`
ServiceDocumentation *string `json:"service_documentation,omitempty"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
ResponseTypesSupported []string `json:"response_types_supported"`
CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported"`
TokenEndpoint string `json:"token_endpoint"`
TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported"`
GrantTypesSupported []string `json:"grant_types_supported"`
RegistrationEndpoint string `json:"registration_endpoint,omitempty"`
}
type OAuthClientInformation ¶ added in v0.2.9
type OAuthClientInformation struct {
// Fields from client metadata
OAuthClientMetadata
// Generated fields
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret,omitempty"`
ClientIDIssuedAt int64 `json:"client_id_issued_at"`
ClientSecretExpiresAt int64 `json:"client_secret_expires_at,omitempty"`
}
OAuthClientInformation represents the full client information including credentials
type OAuthClientMetadata ¶ added in v0.2.9
type OAuthClientMetadata struct {
// Required fields
RedirectURIs []string `json:"redirect_uris"`
// Optional fields
ClientName string `json:"client_name,omitempty"`
ClientURI string `json:"client_uri,omitempty"`
LogoURI string `json:"logo_uri,omitempty"`
Scope string `json:"scope,omitempty"`
GrantTypes []string `json:"grant_types,omitempty"`
ResponseTypes []string `json:"response_types,omitempty"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method,omitempty"`
ContactsEmails []string `json:"contacts,omitempty"`
PolicyURI string `json:"policy_uri,omitempty"`
TermsOfServiceURI string `json:"tos_uri,omitempty"`
JwksURI string `json:"jwks_uri,omitempty"`
SoftwareID string `json:"software_id,omitempty"`
SoftwareVersion string `json:"software_version,omitempty"`
}
OAuthClientMetadata represents the metadata for a dynamically registered OAuth client
type OAuthError ¶ added in v0.2.9
OAuthError represents an OAuth 2.0 error
func (*OAuthError) Error ¶ added in v0.2.9
func (e *OAuthError) Error() string
Error implements the error interface
func (*OAuthError) ToResponseObject ¶ added in v0.2.9
func (e *OAuthError) ToResponseObject() OAuthErrorResponse
ToResponseObject converts the error to a response object
func (*OAuthError) WithDescription ¶ added in v0.2.9
func (e *OAuthError) WithDescription(description string) *OAuthError
WithDescription returns a copy of the error with a new description
type OAuthErrorResponse ¶ added in v0.2.9
type OAuthErrorResponse struct {
Error string `json:"error"`
Description string `json:"error_description,omitempty"`
}
OAuthErrorResponse represents an OAuth 2.0 error response
func NewOAuthErrorResponse ¶ added in v0.2.9
func NewOAuthErrorResponse(err error) OAuthErrorResponse
NewOAuthErrorResponse creates a new OAuth error response
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
func (*Plugin) HandleAuthorize ¶
func (p *Plugin) HandleAuthorize(w http.ResponseWriter, r *http.Request)
func (*Plugin) HandleCallback ¶
func (p *Plugin) HandleCallback(w http.ResponseWriter, r *http.Request)
func (*Plugin) HandleRegister ¶ added in v0.2.9
func (p *Plugin) HandleRegister(w http.ResponseWriter, r *http.Request)
HandleRegister handles OAuth client registration requests
func (*Plugin) HandleToken ¶ added in v0.2.9
func (p *Plugin) HandleToken(w http.ResponseWriter, r *http.Request)
HandleToken handles OAuth token requests
func (*Plugin) RegisterRoutes ¶
func (*Plugin) Wrap ¶
func (p *Plugin) Wrap(connector connectors.Connector) (connectors.Connector, error)
type PluginBundle ¶
type PluginBundle interface {
plugins.Wrapper
plugins.Swaggerer
plugins.HTTPServer
plugins.MCPToolEnricher
}
func New ¶
func New(cfg Config) (PluginBundle, error)
type RegistrationHandlerOptions ¶ added in v0.2.9
type RegistrationHandlerOptions struct {
// ClientSecretExpirySeconds is the expiry time for client secrets in seconds
// If 0, client secrets won't expire (not recommended)
ClientSecretExpirySeconds int64
// RateLimitRequests is the maximum number of requests per hour
// If 0, rate limiting is disabled
RateLimitRequests float64
}
RegistrationHandlerOptions contains options for the client registration handler
type SimpleRateLimiter ¶ added in v0.2.9
type SimpleRateLimiter struct {
// contains filtered or unexported fields
}
SimpleRateLimiter implements a basic rate limiter
func NewSimpleRateLimiter ¶ added in v0.2.9
func NewSimpleRateLimiter(windowSize time.Duration, maxRequest float64) *SimpleRateLimiter
NewSimpleRateLimiter creates a new rate limiter
func (*SimpleRateLimiter) Allow ¶ added in v0.2.9
func (r *SimpleRateLimiter) Allow(key string) bool
Allow checks if a request should be allowed
type TokenHandlerOptions ¶ added in v0.2.9
type TokenHandlerOptions struct {
// RateLimitRequests is the maximum number of requests per window
// If 0, rate limiting is disabled
RateLimitRequests float64
}
TokenHandlerOptions contains options for the token endpoint handler
type TokenRequest ¶ added in v0.2.9
type TokenRequest struct {
GrantType string `json:"grant_type"`
Code string `json:"code,omitempty"`
CodeVerifier string `json:"code_verifier,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Scope string `json:"scope,omitempty"`
RedirectURI string `json:"redirect_uri,omitempty"`
}
TokenRequest represents a request to the token endpoint