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(_ context.Context, clientID, clientSecret, authURL string, logger *slog.Logger) *GitHubHandler
NewGitHubHandler returns a new Handler for GitHub.
func (GitHubHandler) GetUserEmailAddress ¶ added in v0.3.0
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 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(ctx context.Context, code string) (string, error) }
A Handler performs the OAuth handshake and get the email address for the authenticated user.