Documentation
¶
Index ¶
- func DeleteClientInfo(cacheDir, serverHash string) error
- func DeleteFile(cacheDir, serverHash, filename string) error
- func DeleteTokens(cacheDir, serverHash string) error
- func FindAvailablePort(preferred int) (int, error)
- func ReadJSON(cacheDir, serverHash, filename string, v any) error
- func SaveClientInfo(cacheDir, serverHash string, info *ClientInfo) error
- func SaveTokens(cacheDir, serverHash string, tokens *Tokens) error
- func WriteJSON(cacheDir, serverHash, filename string, v any) error
- type CallbackServer
- type ClientInfo
- type ClientMetadata
- type PKCE
- type Provider
- func (p *Provider) ExchangeCode(ctx context.Context, code string) error
- func (p *Provider) GetAccessToken(ctx context.Context) (string, error)
- func (p *Provider) GetAuthorizationURL(resource string) (string, error)
- func (p *Provider) HasValidTokens() bool
- func (p *Provider) Initialise(ctx context.Context) error
- func (p *Provider) Port() int
- func (p *Provider) RefreshToken(ctx context.Context) error
- type ProviderConfig
- type ServerMetadata
- type Tokens
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteClientInfo ¶
DeleteClientInfo removes stored client info.
func DeleteFile ¶
DeleteFile removes a file from the cache directory.
func DeleteTokens ¶
DeleteTokens removes stored tokens.
func FindAvailablePort ¶
FindAvailablePort finds an available port starting from the preferred port.
func SaveClientInfo ¶
func SaveClientInfo(cacheDir, serverHash string, info *ClientInfo) error
SaveClientInfo persists client info to the cache directory.
func SaveTokens ¶
SaveTokens persists tokens to the cache directory.
Types ¶
type CallbackServer ¶
type CallbackServer struct {
// contains filtered or unexported fields
}
CallbackServer handles OAuth callback redirects.
func NewCallbackServer ¶
func NewCallbackServer(port int) (*CallbackServer, error)
NewCallbackServer creates a new callback server.
func (*CallbackServer) Close ¶
func (cs *CallbackServer) Close() error
Close stops the callback server.
func (*CallbackServer) Port ¶
func (cs *CallbackServer) Port() int
Port returns the port the server is listening on.
func (*CallbackServer) WaitForCode ¶
WaitForCode waits for the authorisation code.
type ClientInfo ¶
type ClientInfo struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret,omitempty"`
ClientIDIssuedAt int64 `json:"client_id_issued_at,omitempty"`
ClientSecretExpiresAt int64 `json:"client_secret_expires_at,omitempty"`
RedirectURIs []string `json:"redirect_uris"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method,omitempty"`
GrantTypes []string `json:"grant_types,omitempty"`
ResponseTypes []string `json:"response_types,omitempty"`
ClientName string `json:"client_name,omitempty"`
ClientURI string `json:"client_uri,omitempty"`
Scope string `json:"scope,omitempty"`
}
ClientInfo holds OAuth client registration information.
func LoadClientInfo ¶
func LoadClientInfo(cacheDir, serverHash string) (*ClientInfo, error)
LoadClientInfo loads client info from the cache directory.
type ClientMetadata ¶
type ClientMetadata struct {
RedirectURIs []string `json:"redirect_uris"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method,omitempty"`
GrantTypes []string `json:"grant_types,omitempty"`
ResponseTypes []string `json:"response_types,omitempty"`
ClientName string `json:"client_name,omitempty"`
ClientURI string `json:"client_uri,omitempty"`
Scope string `json:"scope,omitempty"`
SoftwareID string `json:"software_id,omitempty"`
SoftwareVersion string `json:"software_version,omitempty"`
}
ClientMetadata holds OAuth client metadata for registration.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements OAuth authentication for MCP.
func NewProvider ¶
func NewProvider(cfg *ProviderConfig) *Provider
NewProvider creates a new OAuth provider.
func (*Provider) ExchangeCode ¶
ExchangeCode exchanges an authorisation code for tokens.
func (*Provider) GetAccessToken ¶
GetAccessToken returns the current access token.
func (*Provider) GetAuthorizationURL ¶
GetAuthorizationURL returns the OAuth authorisation URL.
func (*Provider) HasValidTokens ¶
HasValidTokens returns true if valid tokens are available.
func (*Provider) Initialise ¶
Initialise prepares the OAuth provider for authentication.
type ProviderConfig ¶
type ProviderConfig struct {
ServerURL string
ServerHash string
CallbackPort int
CallbackHost string
ClientName string
CacheDir string
StaticClientInfo *ClientInfo
StaticClientMetadata *ClientMetadata
}
ProviderConfig holds configuration for the auth provider.
type ServerMetadata ¶
type ServerMetadata struct {
Issuer string `json:"issuer"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
TokenEndpoint string `json:"token_endpoint"`
RegistrationEndpoint string `json:"registration_endpoint,omitempty"`
ScopesSupported []string `json:"scopes_supported,omitempty"`
ResponseTypesSupported []string `json:"response_types_supported,omitempty"`
GrantTypesSupported []string `json:"grant_types_supported,omitempty"`
CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported,omitempty"`
TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported,omitempty"`
}
ServerMetadata holds OAuth authorisation server metadata.
func FetchServerMetadata ¶
func FetchServerMetadata(ctx context.Context, serverURL string) (*ServerMetadata, error)
FetchServerMetadata fetches OAuth authorisation server metadata. Follows RFC 8414 and MCP spec for discovery.
func (*ServerMetadata) SupportsPKCE ¶
func (m *ServerMetadata) SupportsPKCE() bool
SupportsPKCE returns true if the server supports PKCE with S256.
func (*ServerMetadata) ValidateScopes ¶
func (m *ServerMetadata) ValidateScopes(requested []string) []string
ValidateScopes validates requested scopes against supported scopes.
type Tokens ¶
type Tokens struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresIn int `json:"expires_in,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
Scope string `json:"scope,omitempty"`
}
Tokens holds OAuth tokens.
func LoadTokens ¶
LoadTokens loads tokens from the cache directory.