oidc

package
v0.53.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package oidc provides HTTP authentication using OpenID Connect.

Index

Constants

View Source
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

func AccessTokenFromContext(ctx context.Context) string

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

func ContextWithAccessToken(ctx context.Context, token string) context.Context

ContextWithAccessToken returns a new context with the provided access token.

func NewContextWithOIDCUserInfo

func NewContextWithOIDCUserInfo(ctx context.Context, userInfo *goth.User) context.Context

NewContextWithOIDCUserInfo returns a new context with the provided OIDC user info.

func OIDCUserInfoFromContext

func OIDCUserInfoFromContext(ctx context.Context) *goth.User

OIDCUserInfoFromContext returns the OIDC user info from the provided context. It returns nil if no user info is found.

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 NewHandler

func NewHandler(config Config, store sessions.Store) *Handler

func (*Handler) AuthRequest added in v0.37.0

func (h *Handler) AuthRequest(r *http.Request) (stdctx.Context, error)

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

func (*Handler) Middleware added in v0.38.1

func (h *Handler) Middleware(next http.Handler) http.Handler

Middleware returns an HTTP middleware for OIDC authentication.

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.

type SessionData

type SessionData struct {
	ID        uuid.UUID
	Principal string
	Provider  string
	User      goth.User
}

SessionData represents the data stored in the session cookie.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL