Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth interface {
OAuth2
IsOAuth2Enabled() bool
GetOAuth2CORS() *config.CORSConfig
GetGoogleOAuth() ExternalOAuth
GetGitHubOAuth() ExternalOAuth
IsGoogleOAuthEnabled() bool
IsGitHubOAuthEnabled() bool
}
Auth defines the authentication oauth interface
type AuthorizationResponse ¶
AuthorizationResponse represents the response from the authorization endpoint
type ClientRegistrationResponse ¶
type ClientRegistrationResponse struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret,omitempty"`
RedirectURIs []string `json:"redirect_uris"`
GrantTypes []string `json:"grant_types"`
ResponseTypes []string `json:"response_types"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method"`
Scope string `json:"scope"`
}
ClientRegistrationResponse represents the response from the client registration endpoint
type ExternalOAuth ¶ added in v0.9.0
type ExternalOAuth interface {
GetAuthURL(state string) string
ExchangeCode(ctx context.Context, code string) (*ExternalTokenResponse, error)
GetUserInfo(ctx context.Context, accessToken string) (*ExternalUserInfo, error)
}
ExternalOAuth defines the interface for external OAuth providers
type ExternalTokenResponse ¶ added in v0.9.0
type ExternalTokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresIn int `json:"expires_in,omitempty"`
Scope string `json:"scope,omitempty"`
}
ExternalTokenResponse represents the response from external OAuth token exchange
type ExternalUserInfo ¶ added in v0.9.0
type ExternalUserInfo struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
Username string `json:"username,omitempty"`
Picture string `json:"picture,omitempty"`
Provider string `json:"provider"`
}
ExternalUserInfo represents user information from external OAuth providers
type GitHubOAuth ¶ added in v0.9.0
type GitHubOAuth struct {
// contains filtered or unexported fields
}
GitHubOAuth implements GitHub OAuth2 provider
func NewGitHubOAuth ¶ added in v0.9.0
func NewGitHubOAuth(logger *zap.Logger, cfg config.GitHubOAuthConfig) *GitHubOAuth
NewGitHubOAuth creates a new GitHub OAuth provider
func (*GitHubOAuth) ExchangeCode ¶ added in v0.9.0
func (gh *GitHubOAuth) ExchangeCode(ctx context.Context, code string) (*ExternalTokenResponse, error)
ExchangeCode exchanges authorization code for access token
func (*GitHubOAuth) GetAuthURL ¶ added in v0.9.0
func (gh *GitHubOAuth) GetAuthURL(state string) string
GetAuthURL returns the GitHub OAuth authorization URL
func (*GitHubOAuth) GetUserInfo ¶ added in v0.9.0
func (gh *GitHubOAuth) GetUserInfo(ctx context.Context, accessToken string) (*ExternalUserInfo, error)
GetUserInfo retrieves user information from GitHub
type GoogleOAuth ¶ added in v0.9.0
type GoogleOAuth struct {
// contains filtered or unexported fields
}
GoogleOAuth implements Google OAuth2 provider
func NewGoogleOAuth ¶ added in v0.9.0
func NewGoogleOAuth(logger *zap.Logger, cfg config.GoogleOAuthConfig) *GoogleOAuth
NewGoogleOAuth creates a new Google OAuth provider
func (*GoogleOAuth) ExchangeCode ¶ added in v0.9.0
func (g *GoogleOAuth) ExchangeCode(ctx context.Context, code string) (*ExternalTokenResponse, error)
ExchangeCode exchanges authorization code for access token
func (*GoogleOAuth) GetAuthURL ¶ added in v0.9.0
func (g *GoogleOAuth) GetAuthURL(state string) string
GetAuthURL returns the Google OAuth authorization URL
func (*GoogleOAuth) GetUserInfo ¶ added in v0.9.0
func (g *GoogleOAuth) GetUserInfo(ctx context.Context, accessToken string) (*ExternalUserInfo, error)
GetUserInfo retrieves user information from Google
type OAuth2 ¶
type OAuth2 interface {
// ServerMetadata returns the server metadata
ServerMetadata(r *http.Request) map[string]interface{}
// Authorize handles the authorization request
Authorize(ctx context.Context, r *http.Request) (*AuthorizationResponse, error)
// Token handles the token request
Token(ctx context.Context, r *http.Request) (*TokenResponse, error)
// Register handles client registration
Register(ctx context.Context, r *http.Request) (*ClientRegistrationResponse, error)
// Revoke handles token revocation
Revoke(ctx context.Context, r *http.Request) error
// ValidateToken validates an access token
ValidateToken(ctx context.Context, token string) error
}
type RegisterRequest ¶
type StorageType ¶
type StorageType string
const ( // StorageTypeMemory represents an in-memory store StorageTypeMemory StorageType = "memory" // StorageTypeRedis represents a Redis-based store StorageTypeRedis StorageType = "redis" )
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 the response from the token endpoint