oidc

package module
v0.0.0-...-3f51155 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 16 Imported by: 0

README

oidc

Cookie based OIDC authentication middleware

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Must

func Must(h func(http.Handler) http.Handler, err error) func(http.Handler) http.Handler

func OpenIDConnect

func OpenIDConnect(iss, clientID, clientSecret string, opts ...Option) (func(http.Handler) http.Handler, error)

OpenIDConnect ...

Types

type AuthHandler

type AuthHandler interface {
	SignIn(http.ResponseWriter, *http.Request)
	SignInCallback(http.ResponseWriter, *http.Request)

	SignOut(http.ResponseWriter, *http.Request)
	SignOutCallback(http.ResponseWriter, *http.Request)

	RenewAccessToken(http.ResponseWriter, *http.Request)
}

type CookieOptions

type CookieOptions struct {
	Name     string // Default: oidc
	Expires  time.Time
	MaxAge   int
	Domain   string
	Path     string
	SameSite http.SameSite
}

CookieOptions is the various cookie options that are configurable for the identity cookie

func DefaultCookieOptions

func DefaultCookieOptions() CookieOptions

type Option

type Option func(*Options)

Option is the type used to modify the default Options

func WithCookieOptions

func WithCookieOptions(c CookieOptions) Option

func WithPostSignInHandler

func WithPostSignInHandler(h http.Handler) Option

WithPostSignInHandler can be used to customise Post SignIn Redirection

func WithPostSignInHandlerFunc

func WithPostSignInHandlerFunc(h func(w http.ResponseWriter, r *http.Request)) Option

WithPostSignInHandler can be used to customise Post SignIn Redirection

type Options

type Options struct {
	Issuer string

	CookieOptions CookieOptions

	Prefix string

	SignInPath  string
	SignOutPath string

	SignInCallbackPath  string
	SignOutCallbackPath string

	PostSignInRedirect  string
	PostSignOutRedirect string

	RenewTokenPath string
	ResponseType   string
	ResponseMode   ResponseMode

	PostSignInRedirectHandler  http.Handler
	PostSignOutRedirectHandler http.Handler

	Provider oidc.Provider
	Config   oauth2.Config

	NotFoundHandler http.Handler

	Client http.Client

	ErrorLogger *log.Logger

	TempCodec         securecookie.Codec
	RedirectionMaxAge int

	IDTokenVerifier *oidc.IDTokenVerifier
	LogoutURI       string

	AuthHandler AuthHandler
}

Options is the configuration required for running the oidc server

func DefaultOptions

func DefaultOptions() Options

DefaultOptions ...

func (*Options) AuthCookie

func (o *Options) AuthCookie(w http.ResponseWriter, r *http.Request) (*Token, error)

func (*Options) RemoveAuthCookie

func (o *Options) RemoveAuthCookie(w http.ResponseWriter)

func (*Options) RenewAccessToken

func (o *Options) RenewAccessToken(w http.ResponseWriter, r *http.Request)

func (*Options) RenewAccessTokenCall

func (o *Options) RenewAccessTokenCall(w http.ResponseWriter, r *http.Request) (error, string)

func (*Options) SetAuthCookie

func (o *Options) SetAuthCookie(w http.ResponseWriter, r *http.Request, token *Token) error

func (*Options) SignIn

func (o *Options) SignIn(w http.ResponseWriter, r *http.Request)

func (*Options) SignInCallback

func (o *Options) SignInCallback(w http.ResponseWriter, r *http.Request)

func (*Options) SignOut

func (o *Options) SignOut(w http.ResponseWriter, r *http.Request)

func (*Options) SignOutCallback

func (o *Options) SignOutCallback(w http.ResponseWriter, r *http.Request)

type ResponseMode

type ResponseMode = string

ResponseMode ..

const (
	// ResponseModeFormPost ...
	ResponseModeFormPost ResponseMode = "form_post"
	// ResponseModeQuery ..
	ResponseModeQuery ResponseMode = "query"
)

type Token

type Token struct {
	// AccessToken is the token that authorizes and authenticates
	// the requests.
	AccessToken string `json:"access_token"`

	// TokenType is the type of token.
	// The Type method returns either this or "Bearer", the default.
	TokenType string `json:"token_type,omitempty"`

	// RefreshToken is a token that's used by the application
	// (as opposed to the user) to refresh the access token
	// if it expires.
	RefreshToken string `json:"refresh_token,omitempty"`

	// Expiry is the optional expiration time of the access token.
	//
	// If zero, TokenSource implementations will reuse the same
	// token forever and RefreshToken or equivalent
	// mechanisms for that TokenSource will not be used.
	Expiry time.Time `json:"expiry,omitempty"`

	// IDToken is the OpenID addition to the excellent OAuth 2.0
	IDToken string `json:"id_token,omitempty"`
}

Jump to

Keyboard shortcuts

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