Documentation
¶
Index ¶
- Constants
- func GenerateProviders(ctx context.Context, config Config, redirectURL string) (pp map[string]Provider, err error)
- func GetClaimsFromRequest(r *http.Request) (claims *jwt.Claims, ok bool)
- type Auth
- type Config
- type GitHubProvider
- func (p *GitHubProvider) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
- func (p *GitHubProvider) DisplayName() string
- func (p *GitHubProvider) Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (p *GitHubProvider) GetIdentity(ctx context.Context, token *oauth2.Token) (userID string, userName string, err error)
- type OIDCClaims
- type OIDCProvider
- func (p *OIDCProvider) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
- func (p *OIDCProvider) DisplayName() string
- func (p *OIDCProvider) Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (p *OIDCProvider) GetIdentity(ctx context.Context, token *oauth2.Token) (userID string, userName string, err error)
- type Provider
- type ProviderConfig
- type ProviderType
Constants ¶
View Source
const ( ProviderGitHub = "github" ProviderOIDC = "oidc" )
Variables ¶
This section is empty.
Functions ¶
func GenerateProviders ¶
Types ¶
type Auth ¶
func (*Auth) CallBack ¶
func (a *Auth) CallBack() http.HandlerFunc
CallBack is the handler called after login.
It:
1. Fetches the accessToken 2. Fetches some user info and wrap them in a JWT token 3. Store the JWT token in a cookie for the browser.
func (*Auth) Login ¶
func (a *Auth) Login() http.HandlerFunc
Login is the handler that redirect to the authentication page of the OAuth Provider.
func (*Auth) Logout ¶
func (a *Auth) Logout() http.HandlerFunc
type Config ¶
type Config struct {
Providers []ProviderConfig `yaml:"providers"`
}
type GitHubProvider ¶ added in v1.3.0
func (*GitHubProvider) AuthCodeURL ¶ added in v1.3.0
func (p *GitHubProvider) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
func (*GitHubProvider) DisplayName ¶ added in v1.3.0
func (p *GitHubProvider) DisplayName() string
func (*GitHubProvider) Exchange ¶ added in v1.3.0
func (p *GitHubProvider) Exchange( ctx context.Context, code string, opts ...oauth2.AuthCodeOption, ) (*oauth2.Token, error)
func (*GitHubProvider) GetIdentity ¶ added in v1.3.0
type OIDCClaims ¶
type OIDCClaims struct {
jwt.RegisteredClaims
Name string `json:"name"`
Email string `json:"email"`
}
type OIDCProvider ¶ added in v1.3.0
func (*OIDCProvider) AuthCodeURL ¶ added in v1.3.0
func (p *OIDCProvider) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
func (*OIDCProvider) DisplayName ¶ added in v1.3.0
func (p *OIDCProvider) DisplayName() string
func (*OIDCProvider) Exchange ¶ added in v1.3.0
func (p *OIDCProvider) Exchange( ctx context.Context, code string, opts ...oauth2.AuthCodeOption, ) (*oauth2.Token, error)
func (*OIDCProvider) GetIdentity ¶ added in v1.3.0
type Provider ¶
type Provider interface {
AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
DisplayName() string
GetIdentity(
ctx context.Context,
token *oauth2.Token,
) (userID string, userName string, err error)
}
type ProviderConfig ¶
type ProviderConfig struct {
Type ProviderType `yaml:"type"`
Name string `yaml:"name"`
ClientID string `yaml:"clientID"`
ClientSecret string `yaml:"clientSecret"`
Endpoint string `yaml:"endpoint"`
}
type ProviderType ¶
type ProviderType string
Click to show internal directories.
Click to hide internal directories.