Documentation
¶
Overview ¶
Package oidc provides HTTP authentication using OpenID Connect.
Index ¶
- Constants
- func AccessTokenFromContext(ctx context.Context) string
- func ContextWithAccessToken(ctx context.Context, token string) context.Context
- func NewContextWithOIDCUserInfo(ctx context.Context, userInfo *goth.User) context.Context
- func OIDCUserInfoFromContext(ctx context.Context) *goth.User
- type Config
- type Handler
- func (h *Handler) AuthRequest(r *http.Request) (stdctx.Context, error)
- func (h *Handler) AuthStart() http.HandlerFunc
- func (h *Handler) AuthWrapper(next http.HandlerFunc) http.HandlerFunc
- func (h *Handler) Callback() http.HandlerFunc
- func (h *Handler) LogoutHandler() http.HandlerFunc
- func (h *Handler) Middleware(next http.Handler) http.Handler
- type ProviderConfig
- type ProviderMap
- type SessionData
Constants ¶
const ( // SessionCookieName is the name of the cookie used to store the OIDC session. SessionCookieName = "dioad_session" // PreAuthRefererCookieName is the name of the cookie used to store the referer URL before authentication. PreAuthRefererCookieName = "auth_referer" )
Variables ¶
This section is empty.
Functions ¶
func AccessTokenFromContext ¶ added in v0.52.0
AccessTokenFromContext returns the access token from the provided context. It returns an empty string if no token is found.
func ContextWithAccessToken ¶ added in v0.52.0
ContextWithAccessToken returns a new context with the provided access token.
func NewContextWithOIDCUserInfo ¶
NewContextWithOIDCUserInfo returns a new context with the provided OIDC user info.
Types ¶
type Config ¶
type Config struct {
ProviderMap ProviderMap `mapstructure:"providers"`
CookieConfig http.CookieConfig `mapstructure:"cookies"`
}
Config contains configuration for OIDC authentication.
type Handler ¶
type Handler struct {
CookieStore sessions.Store
LoginPath string
LogoutPath string
CallbackDefaultRedirect string
HomePath string
}
Handler implements OIDC-based authentication using the gothic library.
func (*Handler) AuthRequest ¶ added in v0.37.0
AuthRequest authenticates an HTTP request by checking for a valid OIDC session cookie.
func (*Handler) AuthStart ¶
func (h *Handler) AuthStart() http.HandlerFunc
AuthStart returns an HTTP handler function that starts the OIDC authentication flow.
func (*Handler) AuthWrapper ¶
func (h *Handler) AuthWrapper(next http.HandlerFunc) http.HandlerFunc
AuthWrapper wraps an HTTP handler function with OIDC authentication. If the user is not authenticated, they are redirected to the login path.
func (*Handler) Callback ¶
func (h *Handler) Callback() http.HandlerFunc
func (*Handler) LogoutHandler ¶
func (h *Handler) LogoutHandler() http.HandlerFunc
type ProviderConfig ¶
type ProviderConfig struct {
ClientID string `mapstructure:"client-id"`
ClientSecret string `mapstructure:"client-secret"`
Callback string `mapstructure:"callback"`
Scopes []string `mapstructure:"scopes"` // OAuth2 Scopes - Optional
DiscoveryURL string `mapstructure:"discovery-url"` // OpenID Connect Discovery URL - Optional
}
ProviderConfig contains configuration for an OIDC provider.
type ProviderMap ¶
type ProviderMap map[string]ProviderConfig
ProviderMap maps provider names to their configurations.