Documentation ¶
Overview ¶
Package oauth implements handlers for traefik-simple-auth to authenticate a user. It implements the oauth2 handshake, as well as a means to get the email address of the authenticated users.
Currently, Google and GitHub are supported as oauth2 providers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseHandler ¶ added in v0.3.0
BaseHandler implements the generic part of a Handler.
type GitHubHandler ¶ added in v0.3.0
type GitHubHandler struct {
BaseHandler
}
GitHubHandler performs the OAuth handshake using GitHub as authenticator and gets the email address for the authenticated user.
func NewGitHubHandler ¶ added in v0.3.0
func NewGitHubHandler(clientID, clientSecret, authURL string, logger *slog.Logger) *GitHubHandler
NewGitHubHandler returns a new Handler for GitHub.
func (GitHubHandler) GetUserEmailAddress ¶ added in v0.3.0
func (h GitHubHandler) GetUserEmailAddress(code string) (string, error)
GetUserEmailAddress returns the email address of the authenticated user.
For GitHub, we first check the user's profile. If the user's email address if marked as public, that email address is returned. Otherwise, we check the different email addresses for that user. If one is marked as primary, that email address is returned. Otherwise, we return the first email address in the list.
type GoogleHandler ¶ added in v0.3.0
type GoogleHandler struct {
BaseHandler
}
GoogleHandler performs the OAuth handshake using Google as authenticator and gets the email address for the authenticated user.
func NewGoogleHandler ¶ added in v0.3.0
func NewGoogleHandler(clientID, clientSecret, authURL string, logger *slog.Logger) *GoogleHandler
NewGoogleHandler returns a new Handler for Google.
func (GoogleHandler) GetUserEmailAddress ¶ added in v0.3.0
func (h GoogleHandler) GetUserEmailAddress(code string) (string, error)
GetUserEmailAddress returns the email address of the authenticated user.
type Handler ¶
type Handler interface { // AuthCodeURL generates the URL to use in the oauth2 handshake. AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string // GetUserEmailAddress returns the email address of the authenticated user. GetUserEmailAddress(code string) (string, error) }
A Handler performs the OAuth handshake and get the email address for the authenticated user.