Documentation
¶
Overview ¶
Package github provides GitHub-based authentication middleware.
Index ¶
- func LoadAccessTokenFromFile(filePath string) (*api.AccessToken, error)
- func NewContextWithGitHubUserInfo(ctx context.Context, userInfo *UserInfo) context.Context
- func ResolveAccessToken(c ClientConfig) (string, error)
- func SaveAccessTokenToFile(accessToken *api.AccessToken, authFilePath string) error
- type Authenticator
- type ClientAuth
- type ClientConfig
- type CommonConfig
- type Handler
- type ServerConfig
- type TokenRoundTripper
- type TokenSource
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadAccessTokenFromFile ¶
func LoadAccessTokenFromFile(filePath string) (*api.AccessToken, error)
LoadAccessTokenFromFile loads a GitHub access token from a file.
func NewContextWithGitHubUserInfo ¶
NewContextWithGitHubUserInfo returns a new context with the provided GitHub user info.
func ResolveAccessToken ¶
func ResolveAccessToken(c ClientConfig) (string, error)
ResolveAccessToken determines the GitHub access token to use based on configuration. It checks environment variables if configured, falls back to a file if AccessToken is not directly provided in the config.
func SaveAccessTokenToFile ¶
func SaveAccessTokenToFile(accessToken *api.AccessToken, authFilePath string) error
SaveAccessTokenToFile saves a GitHub access token to a file.
Types ¶
type Authenticator ¶
type Authenticator struct {
Config ServerConfig
Client *github.Client
}
Authenticator handles GitHub token validation using the GitHub API.
func NewGitHubAuthenticator ¶
func NewGitHubAuthenticator(cfg ServerConfig) *Authenticator
NewGitHubAuthenticator creates a new GitHub Authenticator with the provided configuration.
func (*Authenticator) AuthenticateToken ¶
func (a *Authenticator) AuthenticateToken(accessToken string) (*UserInfo, error)
AuthenticateToken verifies the provided GitHub access token against the GitHub API. It also fetches additional user information if the token is valid.
type ClientAuth ¶ added in v0.40.0
type ClientAuth struct {
Config ClientConfig
// contains filtered or unexported fields
}
ClientAuth implements authentication for a GitHub client.
func (ClientAuth) AddAuth ¶ added in v0.40.0
func (a ClientAuth) AddAuth(req *http.Request) error
AddAuth adds the GitHub access token to the request's Authorization header.
func (ClientAuth) HTTPClient ¶ added in v0.40.0
func (a ClientAuth) HTTPClient() *http.Client
type ClientConfig ¶ added in v0.37.0
type ClientConfig struct {
CommonConfig `mapstructure:",squash"`
AccessToken string `mapstructure:"access-token"`
AccessTokenFile string `mapstructure:"access-token-file"`
EnableAccessTokenFromEnvironment bool `mapstructure:"enable-access-token-from-environment"`
EnvironmentVariableName string `mapstructure:"environment-variable-name"`
}
ClientConfig contains configuration for a GitHub authentication client.
type CommonConfig ¶ added in v0.37.0
type CommonConfig struct {
AllowInsecureHTTP bool `mapstructure:"allow-insecure-http"`
ClientID string `mapstructure:"client-id"`
ClientSecret string `mapstructure:"client-secret"`
// ConfigFile containing ClientID and ClientSecret
ConfigFile string `mapstructure:"config-file"`
}
CommonConfig contains shared configuration for GitHub authentication.
type Handler ¶ added in v0.37.0
type Handler struct {
Authenticator *Authenticator
}
Handler implements GitHub token authentication.
func NewHandler ¶ added in v0.37.0
func NewHandler(cfg ServerConfig) *Handler
NewHandler creates a new GitHub authentication handler with the provided configuration.
func (*Handler) AuthRequest ¶ added in v0.37.0
AuthRequest authenticates an HTTP request using a GitHub token. It expects a "Bearer" or "Token" Authorization header.
type ServerConfig ¶ added in v0.37.0
type ServerConfig struct {
CommonConfig `mapstructure:",squash"`
PrincipalACLConfig authz.PrincipalACLConfig `mapstructure:"principals"`
}
ServerConfig contains configuration for a GitHub authentication server.
func FromMap ¶ added in v0.37.0
func FromMap(m map[string]interface{}) ServerConfig
FromMap creates a ServerConfig from a map.
type TokenRoundTripper ¶ added in v0.40.0
type TokenRoundTripper struct {
Source oauth2.TokenSource
Base http.RoundTripper
}
TokenRoundTripper is an http.RoundTripper that adds an OAuth2 token to requests.
type TokenSource ¶
type TokenSource struct {
AccessToken string
}
TokenSource implements the oauth2.TokenSource interface for a static GitHub token.
type UserInfo ¶
type UserInfo struct {
Login string
Name string
PrimaryEmail string
PrimaryEmailVerified bool
Company string
WebSite string
Location string
PlanName string
}
UserInfo contains information about a GitHub user.
func FetchUserInfo ¶
FetchUserInfo retrieves GitHub user information using the provided access token. It fetches basic profile info and the primary email address.
func GitHubUserInfoFromContext ¶
GitHubUserInfoFromContext returns the GitHub user info from the provided context. It returns nil if no user info is found.