oidc

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCookieDomain          = "localhost"
	DefaultCookiePath            = "/"
	DefaultTokenCookieName       = "oidc_token"
	DefaultTokenCookieMaxAge     = time.Hour
	DefaultStateCookieName       = "oidc_state"
	DefaultStateCookieMaxAge     = 5 * time.Minute
	DefaultRefreshCookieName     = "oidc_refresh"
	DefaultRefreshCookieMaxAge   = 24 * time.Hour
	DefaultTokenExpiryCookieName = "oidc_expires_in"
)

Functions

func AccessTokenFromContext

func AccessTokenFromContext(ctx context.Context) string

func ContextWithAccessToken

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

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.

Types

type CookieConfig

type CookieConfig struct {
	Name   string        `json:"name" mapstructure:"name"`
	Domain string        `json:"domain,omitzero" mapstructure:"domain,omitzero"`
	Secure bool          `json:"secure,omitzero" mapstructure:"secure,omitzero"`
	Path   string        `json:"path,omitzero" mapstructure:"path,omitzero"`
	MaxAge time.Duration `json:"max_age,omitzero" mapstructure:"max-age,omitzero"`
}

func (CookieConfig) Cookie

func (c CookieConfig) Cookie(value string) *http.Cookie

func (CookieConfig) Delete

func (c CookieConfig) Delete(w http.ResponseWriter)

func (CookieConfig) Set

func (c CookieConfig) Set(w http.ResponseWriter, value string)

type Handler

type Handler struct {
	Client *oidc.Client
	Config OIDCConfig
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(client *oidc.Client, cfg OIDCConfig, logger zerolog.Logger) *Handler

func (*Handler) AuthStart

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

AuthStart initiates the OIDC authentication flow.

func (*Handler) Callback

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

Callback handles the OIDC provider callback and sets cookies.

func (*Handler) Logout

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

Logout clears all authentication cookies and redirects to root.

func (*Handler) Wrap

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

type OIDCConfig

type OIDCConfig struct {
	Scopes      []string `json:"scopes,omitzero" mapstructure:"scopes,omitzero"`
	RedirectURI string   `json:"redirect_uri,omitzero" mapstructure:"redirect-uri,omitzero"`

	TokenCookie       CookieConfig `json:"token_cookie,omitzero" mapstructure:"token-cookie,omitzero"`
	StateCookie       CookieConfig `json:"state_cookie,omitzero" mapstructure:"state-cookie,omitzero"`
	RefreshCookie     CookieConfig `json:"refresh_cookie,omitzero" mapstructure:"refresh-cookie,omitzero"`
	TokenExpiryCookie CookieConfig `json:"token_expiry,omitzero" mapstructure:"token-expiry,omitzero"`
	RedirectCookie    CookieConfig `json:"redirect_cookie,omitzero" mapstructure:"redirect-cookie,omitzero"`

	RefreshWindow time.Duration    `json:"refresh_window,omitzero" mapstructure:"refresh-window,omitzero"`
	Now           func() time.Time `json:"-,omitzero" mapstructure:"-,omitzero"`
	LoginPath     string           `json:"login_path,omitzero" mapstructure:"login-path,omitzero"`
}

Jump to

Keyboard shortcuts

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