chistd

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MPL-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package chistd includes common utilities and functions for setting up and using go-chi.

Index

Constants

View Source
const (
	// URL paths
	OIDCRegisterPath = "/oidc/register"
	OIDCLoginPath    = "/oidc/login"
	OIDCLogoutPath   = "/oidc/logout"
	OIDCCallbackPath = "/oidc/callback"

	// Session keys
	IDTokenSessionKey           = "id_token"
	AccessTokenSessionKey       = "access_token"
	AccessTokenExpirySessionKey = "access_token_expiry"
	RefreshTokenSessionKey      = "refresh_token"
	UserProfileSessionKey       = "profile"
	ContinueToURLSessionKey     = "continue_to"
	PKCECodeVerifierSessionKey  = "pkce_code_verifier"
)

Variables

This section is empty.

Functions

func AddDefaultMiddlewares

func AddDefaultMiddlewares(router chi.Router, opts DefaultMiddlewareOptions)

AddDefaultMiddlewares adds all the chi middlewares that we want for applied to all requests.

func AddNosurfMiddleware

func AddNosurfMiddleware(cfg *webstd.CSRF, router chi.Router)

AddNosurfMiddleware will add the nosurf middleware into the chi stack.

func AddStaticRoutes

func AddStaticRoutes(logger *zap.Logger, router chi.Router, staticFS embed.FS) error

AddStaticRoutes creates routes for static assets. This will directly serve static files under the /static route, but also serve some favicon related files from the root path.

func NewRouterWithDefaultMiddlewares

func NewRouterWithDefaultMiddlewares(opts DefaultMiddlewareOptions) chi.Router

NewRouterWithDefaultMiddlewares returns a new go-chi router that has a set of recommended default routers configured.

Types

type DefaultMiddlewareOptions

type DefaultMiddlewareOptions struct {
	Logger          *zap.Logger
	ErrorMiddleware func(http.Handler) http.Handler
	Concise         bool
	SkipURLParams   []string
	SkipHeaders     []string
}

type OIDCHandlerContext

type OIDCHandlerContext[T any] struct {
	// contains filtered or unexported fields
}

func NewOIDCHandlerContext

func NewOIDCHandlerContext[T any](
	logger *zap.Logger,
	auth *webstd.Authenticator,
	sessMgr *scs.SessionManager,
	homePath string,
) *OIDCHandlerContext[T]

NewOIDCHandlerContext returns a new handler context for the OIDC pages. The generic type parameter represents the profile struct to marshal the ID token claims to.

func (OIDCHandlerContext[T]) AddOIDCHandlerRoutes

func (h OIDCHandlerContext[T]) AddOIDCHandlerRoutes(router chi.Router)

AddOIDCHandlerRoutes will add a group of routes that can be used to implement OIDC client protocol to manage authentication into an existing go-chi based web app. Note that this depends on the following two middlewares: - github.com/alexedwards/scs/v2 - github.com/ory/nosurf

Jump to

Keyboard shortcuts

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