authentication

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGroups

func GetGroups(ctx context.Context) ([]string, bool)

GetGroups extracts the groups from provided context.

func GetSubject

func GetSubject(ctx context.Context) (string, bool)

GetSubject extracts the subject from provided context.

func GetTenant

func GetTenant(ctx context.Context) (string, bool)

GetTenant extracts the tenant from provided context.

func NewMTLS

func NewMTLS(configs []MTLSConfig) map[string]Middleware

NewMTLS creates a set of Middlewares for all specified tenants.

func NewOIDC

func NewOIDC(logger log.Logger, prefix string, configs []TenantOIDCConfig) (http.Handler, map[string]Middleware, []error)

NewOIDC creates a single http.Handler and a set of Middlewares for all tenants that is able to authenticate requests and provide the authorization code grant flow for users.

func WithTenant

func WithTenant(next http.Handler) http.Handler

WithTenant finds the tenant from the URL parameters and adds it to the request context.

Types

type MTLSConfig

type MTLSConfig struct {
	Tenant string
	CAs    []*x509.Certificate
}

MTLSConfig represents the mTLS configuration for a single tenant.

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is a convenience type for functions that wrap http.Handlers.

func WithTenantHeader

func WithTenantHeader(header string, tenantIDs map[string]string) Middleware

WithTenantHeader returns a new middleware that adds the ID of the tenant to the specified header.

func WithTenantMiddlewares

func WithTenantMiddlewares(middlewareSets ...map[string]Middleware) Middleware

WithTenantMiddlewares creates a single Middleware for all provided tenant-middleware sets.

type OIDCConfig

type OIDCConfig struct {
	IssuerCA      *x509.Certificate
	IssuerURL     string
	ClientID      string
	ClientSecret  string
	GroupClaim    string
	RedirectURL   string
	UsernameClaim string
}

OIDCConfig represents a generic OIDC configuration.

type OIDCProvider

type OIDCProvider struct {
	// contains filtered or unexported fields
}

OIDCProvider wraps the oidc.Provider in an opinionated way to create login and callback handlers as well as HTTP middlewares to authenticate requests against the provider.

func NewProvider

func NewProvider(ctx context.Context, logger log.Logger, cookieName, redirectURL string, config OIDCConfig) (*OIDCProvider, error)

NewProvider creates a new OIDCProvider.

func (*OIDCProvider) CallbackHandler

func (p *OIDCProvider) CallbackHandler() http.Handler

CallbackHandler returns a http.Handler, that is meant to be redirected to after the provider has authenticated the user.

func (*OIDCProvider) LoginHandler

func (p *OIDCProvider) LoginHandler() http.Handler

LoginHandler returns a http.Handler, that starts the OIDC flow.

func (*OIDCProvider) Middleware

func (p *OIDCProvider) Middleware() Middleware

Middleware creates an HTTP middleware, that can be used to wrap a http.Handler to authenticate requests for it.

func (*OIDCProvider) OIDCProvider

func (p *OIDCProvider) OIDCProvider() *oidc.Provider

OIDCProvider returns the internal oidc.Provider, this can be used to for example access the UserInfo function of the provider.

type TenantOIDCConfig

type TenantOIDCConfig struct {
	Tenant string

	OIDCConfig
}

TenantOIDCConfig represents the OIDC configuration for a single tenant.

Jump to

Keyboard shortcuts

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