oidc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package oidc provides HTTP authentication using OpenID Connect via goth.

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

func AccessTokenFromContext(ctx context.Context) *oauth2.Token

AccessTokenFromContext returns the access token from the provided context. It returns a nil value if no token is found.

func ContextWithAccessToken

func ContextWithAccessToken(ctx context.Context, token *oauth2.Token) context.Context

ContextWithAccessToken returns a new context with the provided access token.

func ContextWithOIDCUserInfo

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

ContextWithOIDCUserInfo 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"`
}

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

NewHandler configures OIDC providers and returns a handler.

func (*Handler) AuthRequest

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

Callback handles provider callbacks.

func (*Handler) LogoutHandler

func (h *Handler) LogoutHandler() http.HandlerFunc

LogoutHandler clears authentication state and redirects to login.

func (*Handler) Middleware

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