Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface {
// RequestAuth returns a http.HandlerFunc that redirects the user to the OAuth2 provider for authentication and gets the authorization code.
RequestAuth() http.HandlerFunc
// Callback returns a http.HandlerFunc that exchanges the authorization code for an access token and fetches user info from the OAuth2 provider.
// The parameter is a function that takes the user info and returns the JWT token or an error.
Callback(func(userInfo any) (token *jwt.TokenDetails, err errors.Error)) http.HandlerFunc
// GetTokenByUserID returns the cache token by user ID.
GetTokenByUserID(userId string) (*oauth2.Token, errors.Error)
}
Authenticator is an interface for OAuth2 authenticators.
func NewAuthentikAuthenticator ¶
func NewAuthentikAuthenticator(config Config, lc log.Logger) Authenticator
NewAuthentikAuthenticator creates a new Authenticator for authentik.
type AuthentikAuthenticator ¶
type AuthentikAuthenticator struct {
// contains filtered or unexported fields
}
func (*AuthentikAuthenticator) Callback ¶
func (a *AuthentikAuthenticator) Callback(loginAndGetJWT func(userInfo any) (token *jwt.TokenDetails, err errors.Error)) http.HandlerFunc
Callback returns a http.HandlerFunc that exchanges the authorization code for an access token and fetches user info from the OAuth2 provider. The parameter is a function that takes the user info and returns the JWT token or an error.
func (*AuthentikAuthenticator) GetTokenByUserID ¶
GetTokenByUserID returns the oauth2 token by user ID
func (*AuthentikAuthenticator) RequestAuth ¶
func (a *AuthentikAuthenticator) RequestAuth() http.HandlerFunc
RequestAuth returns a http.HandlerFunc that redirects the user to the OAuth2 provider for authentication.
type AuthentikUserInfo ¶
type AuthentikUserInfo struct {
Sub string `json:"sub"`
Email string `json:"email"`
VerifiedEmail bool `json:"email_verified"`
Name string `json:"name"`
GivenName string `json:"given_name"`
PreferredUsername string `json:"preferred_username"`
Nickname string `json:"nickname"`
Groups []string `json:"groups"`
// Custom fields of a more common name for the user ID
ID string `json:"id"`
}
func (*AuthentikUserInfo) Validate ¶
func (u *AuthentikUserInfo) Validate() error
Validate validates user info
type Config ¶
type Config struct {
GoOAuth2Config *oauth2.Config
UserInfoURL string
RedirectPath string // RedirectPath is the path that the user will be redirected to after login
}
func NewAuthentikConfigs ¶
func NewAuthentikConfigs(clientId, clientSecret, authURL, tokenURL, redirectURL, userInfoURL, redirectPath string) Config
NewAuthentikConfigs returns a new Config for authentik.
func NewGitHubConfigs ¶
NewGitHubConfigs returns a new Config for GitHub.
func NewGoogleConfigs ¶
NewGoogleConfigs returns a new Config for Google.
type GitHubAuthenticator ¶
type GitHubAuthenticator struct {
// contains filtered or unexported fields
}
func NewGitHubAuthenticator ¶
func NewGitHubAuthenticator(config Config, lc log.Logger) *GitHubAuthenticator
func (*GitHubAuthenticator) Callback ¶
func (g *GitHubAuthenticator) Callback(loginAndGetJWT func(userInfo any) (token *jwt.TokenDetails, err errors.Error)) http.HandlerFunc
Callback returns a http.HandlerFunc that exchanges the authorization code for an access token and fetches user info from the OAuth2 provider. The parameter is a function that takes the user info and returns the JWT token or an error.
func (*GitHubAuthenticator) GetTokenByUserID ¶
GetTokenByUserID returns the oauth2 token by user ID
func (*GitHubAuthenticator) RequestAuth ¶
func (g *GitHubAuthenticator) RequestAuth() http.HandlerFunc
RequestAuth returns a http.HandlerFunc that redirects the user to the OAuth2 provider for authentication.
type GitHubUserInfo ¶
type GoogleAuthenticator ¶
type GoogleAuthenticator struct {
// contains filtered or unexported fields
}
func NewGoogleAuthenticator ¶
func NewGoogleAuthenticator(config Config, lc log.Logger) *GoogleAuthenticator
func (*GoogleAuthenticator) Callback ¶
func (g *GoogleAuthenticator) Callback(loginAndGetJWT func(userInfo any) (token *jwt.TokenDetails, err errors.Error)) http.HandlerFunc
Callback returns a http.HandlerFunc that exchanges the authorization code for an access token and fetches user info from the OAuth2 provider. The parameter is a function that takes the user info and returns the JWT token or an error.
func (*GoogleAuthenticator) GetTokenByUserID ¶
GetTokenByUserID returns the oauth2 token by user ID
func (*GoogleAuthenticator) RequestAuth ¶
func (g *GoogleAuthenticator) RequestAuth() http.HandlerFunc
RequestAuth returns a http.HandlerFunc that redirects the user to the OAuth2 provider for authentication.
type GoogleUserInfo ¶
type GoogleUserInfo struct {
ID string `json:"id"`
Email string `json:"email"`
VerifiedEmail bool `json:"verified_email"`
Name string `json:"name"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
Picture string `json:"picture"`
Locale string `json:"locale"`
HostedDomain string `json:"hd"`
}
func (*GoogleUserInfo) Validate ¶
func (u *GoogleUserInfo) Validate() error
Validate validates user info