Documentation
¶
Index ¶
- func GeneratePKCEChallenge() (*types.PKCEChallenge, error)
- func GenerateState() (string, error)
- func ValidatePKCEChallenge(challenge *types.PKCEChallenge, verifier string) error
- type AuthenticationResult
- type AuthenticationSession
- type BrowserAuthFlow
- func (f *BrowserAuthFlow) Authenticate(ctx context.Context) (*TokenResponse, error)
- func (f *BrowserAuthFlow) AuthenticateIfRequired(ctx context.Context, required bool) (*TokenResponse, error)
- func (f *BrowserAuthFlow) AuthenticateWithTimeout(timeout time.Duration) (*TokenResponse, error)
- func (f *BrowserAuthFlow) GetRedirectURI() string
- func (f *BrowserAuthFlow) ValidateConfig() error
- type BrowserLauncher
- type CallbackServer
- type DefaultBrowserLauncher
- type DefaultOAuth2Client
- func (c *DefaultOAuth2Client) DiscoverEndpoints(ctx context.Context) error
- func (c *DefaultOAuth2Client) ExchangeCodeForToken(ctx context.Context, code string, pkce *types.PKCEChallenge, ...) (*TokenResponse, error)
- func (c *DefaultOAuth2Client) StartAuthentication(ctx context.Context) (*AuthenticationSession, error)
- func (c *DefaultOAuth2Client) ValidateConfiguration() error
- type LocalCallbackServer
- type OAuth2Client
- type OAuth2ClientConfig
- type TokenResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GeneratePKCEChallenge ¶
func GeneratePKCEChallenge() (*types.PKCEChallenge, error)
GeneratePKCEChallenge generates a PKCE code challenge and verifier according to RFC7636
func GenerateState ¶
GenerateState generates a cryptographically secure state parameter for OAuth flow
func ValidatePKCEChallenge ¶
func ValidatePKCEChallenge(challenge *types.PKCEChallenge, verifier string) error
ValidatePKCEChallenge validates a PKCE challenge against a verifier
Types ¶
type AuthenticationResult ¶
type AuthenticationResult struct {
Success bool
TokenResponse *TokenResponse
Error error
// Additional metadata
State string
ExchangedAt time.Time
}
AuthenticationResult represents the result of browser-based authentication
type AuthenticationSession ¶
type AuthenticationSession struct {
// PKCE parameters
PKCEChallenge *types.PKCEChallenge
// Session state
State string
RedirectURI string
// Authorization URL
AuthURL string
// Callback server
CallbackServer CallbackServer
// Result channels
ResultCh chan *AuthenticationResult
ErrorCh chan error
// Context for cancellation
Context context.Context
Cancel context.CancelFunc
}
AuthenticationSession represents an ongoing OAuth authentication session
type BrowserAuthFlow ¶
type BrowserAuthFlow struct {
// contains filtered or unexported fields
}
BrowserAuthFlow manages the complete browser-based OAuth authentication flow
func NewBrowserAuthFlow ¶
func NewBrowserAuthFlow(config *OAuth2ClientConfig, logger *logrus.Logger) (*BrowserAuthFlow, error)
NewBrowserAuthFlow creates a new browser authentication flow manager
func (*BrowserAuthFlow) Authenticate ¶
func (f *BrowserAuthFlow) Authenticate(ctx context.Context) (*TokenResponse, error)
Authenticate performs the complete browser-based authentication flow
func (*BrowserAuthFlow) AuthenticateIfRequired ¶
func (f *BrowserAuthFlow) AuthenticateIfRequired(ctx context.Context, required bool) (*TokenResponse, error)
AuthenticateIfRequired performs authentication only if required by configuration
func (*BrowserAuthFlow) AuthenticateWithTimeout ¶
func (f *BrowserAuthFlow) AuthenticateWithTimeout(timeout time.Duration) (*TokenResponse, error)
AuthenticateWithTimeout performs authentication with a custom timeout
func (*BrowserAuthFlow) GetRedirectURI ¶
func (f *BrowserAuthFlow) GetRedirectURI() string
GetRedirectURI returns the redirect URI that would be used for authentication
func (*BrowserAuthFlow) ValidateConfig ¶
func (f *BrowserAuthFlow) ValidateConfig() error
ValidateConfig validates the authentication flow configuration
type BrowserLauncher ¶
BrowserLauncher interface for opening browsers
func NewBrowserLauncher ¶
func NewBrowserLauncher() BrowserLauncher
NewBrowserLauncher creates a new browser launcher
type CallbackServer ¶
type CallbackServer interface {
Start(ctx context.Context, port int) error
Stop() error
GetRedirectURI() string
GetAuthorizationCode() <-chan string
GetError() <-chan error
}
CallbackServer interface for handling OAuth callbacks
func NewCallbackServer ¶
func NewCallbackServer(logger *logrus.Logger) CallbackServer
NewCallbackServer creates a new OAuth callback server
type DefaultBrowserLauncher ¶
type DefaultBrowserLauncher struct{}
DefaultBrowserLauncher implements BrowserLauncher for cross-platform browser opening
func (*DefaultBrowserLauncher) OpenURL ¶
func (b *DefaultBrowserLauncher) OpenURL(url string) error
OpenURL opens a URL in the default system browser
type DefaultOAuth2Client ¶
type DefaultOAuth2Client struct {
// contains filtered or unexported fields
}
DefaultOAuth2Client implements OAuth2Client for browser-based authentication
func (*DefaultOAuth2Client) DiscoverEndpoints ¶
func (c *DefaultOAuth2Client) DiscoverEndpoints(ctx context.Context) error
DiscoverEndpoints discovers OAuth endpoints from the issuer URL using RFC8414 or OpenID Connect Discovery
func (*DefaultOAuth2Client) ExchangeCodeForToken ¶
func (c *DefaultOAuth2Client) ExchangeCodeForToken(ctx context.Context, code string, pkce *types.PKCEChallenge, redirectURI string) (*TokenResponse, error)
ExchangeCodeForToken exchanges an authorization code for an access token
func (*DefaultOAuth2Client) StartAuthentication ¶
func (c *DefaultOAuth2Client) StartAuthentication(ctx context.Context) (*AuthenticationSession, error)
StartAuthentication initiates the OAuth 2.0 authorization code flow with PKCE
func (*DefaultOAuth2Client) ValidateConfiguration ¶
func (c *DefaultOAuth2Client) ValidateConfiguration() error
ValidateConfiguration validates the OAuth client configuration
type LocalCallbackServer ¶
type LocalCallbackServer struct {
// contains filtered or unexported fields
}
LocalCallbackServer implements CallbackServer for localhost OAuth redirects
func (*LocalCallbackServer) GetAuthorizationCode ¶
func (s *LocalCallbackServer) GetAuthorizationCode() <-chan string
GetAuthorizationCode returns a channel that receives the authorization code
func (*LocalCallbackServer) GetError ¶
func (s *LocalCallbackServer) GetError() <-chan error
GetError returns a channel that receives errors
func (*LocalCallbackServer) GetRedirectURI ¶
func (s *LocalCallbackServer) GetRedirectURI() string
GetRedirectURI returns the redirect URI for this callback server
func (*LocalCallbackServer) Start ¶
func (s *LocalCallbackServer) Start(ctx context.Context, port int) error
Start starts the callback server on the specified port (0 for random)
func (*LocalCallbackServer) Stop ¶
func (s *LocalCallbackServer) Stop() error
Stop stops the callback server
type OAuth2Client ¶
type OAuth2Client interface {
// StartAuthentication initiates the OAuth 2.0 authorization code flow
StartAuthentication(ctx context.Context) (*AuthenticationSession, error)
// ExchangeCodeForToken exchanges authorization code for access token
ExchangeCodeForToken(ctx context.Context, code string, pkce *types.PKCEChallenge, redirectURI string) (*TokenResponse, error)
// DiscoverEndpoints discovers OAuth endpoints from issuer URL
DiscoverEndpoints(ctx context.Context) error
// ValidateConfiguration validates the client configuration
ValidateConfiguration() error
}
OAuth2Client interface for browser-based OAuth flows
func NewOAuth2Client ¶
func NewOAuth2Client(config *OAuth2ClientConfig, logger *logrus.Logger) (OAuth2Client, error)
NewOAuth2Client creates a new OAuth 2.0 client for browser authentication
type OAuth2ClientConfig ¶
type OAuth2ClientConfig struct {
// Client credentials
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret,omitempty"` // Optional for public clients
// Authorization server endpoints
AuthorizationEndpoint string `json:"authorization_endpoint"`
TokenEndpoint string `json:"token_endpoint"`
// Optional discovery
IssuerURL string `json:"issuer_url,omitempty"` // For .well-known/oauth-authorization-server discovery
// Redirect configuration
RedirectURI string `json:"redirect_uri"` // Usually http://localhost:PORT/callback
// OAuth parameters
Scope string `json:"scope,omitempty"` // Requested scopes
Resource string `json:"resource,omitempty"` // RFC8707 resource parameter
// Security settings
RequireHTTPS bool `json:"require_https"` // Default true, false only for localhost
// Timeouts
AuthTimeout time.Duration `json:"auth_timeout"` // How long to wait for user authentication
ServerPort int `json:"server_port"` // Port for callback server (0 = random)
}
OAuth2ClientConfig represents OAuth 2.0 client configuration for browser authentication
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int64 `json:"expires_in,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Scope string `json:"scope,omitempty"`
}
TokenResponse represents an OAuth 2.0 token response