tokens

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package tokens manages token authentication

Index

Constants

View Source
const (
	// session cookie stores the session token
	SessionCookie = "session"
)

Variables

AuthenticatedPrefixes are those URL path prefixes requiring authentication.

Functions

func NewTestSessionJWT

func NewTestSessionJWT(t *testing.T, username string, secret []byte, lifetime time.Duration) string

func TokenFlashMessage added in v0.2.0

func TokenFlashMessage(renderer html.Renderer, w http.ResponseWriter, token []byte) error

TokenFlashMessage is a helper for rendering a flash message with an authentication token.

Types

type GoogleIAPConfig

type GoogleIAPConfig struct {
	Audience string
}

type Kind

type Kind string

the Kind of authentication token: user session, user token, agent token, etc

type NewTokenOptions

type NewTokenOptions struct {
	Kind    Kind
	Subject string
	Expiry  *time.Time
	Claims  map[string]string
}

type Options

type Options struct {
	logr.Logger
	GoogleIAPConfig

	Secret []byte
}

type Service added in v0.2.2

type Service struct {
	logr.Logger
	// contains filtered or unexported fields
}

func NewService

func NewService(opts Options) (*Service, error)

func (Service) GetOrCreateUISubject added in v0.2.2

func (r Service) GetOrCreateUISubject(ctx context.Context, login string) (internal.Subject, error)

func (Service) GetSubject added in v0.2.2

func (r Service) GetSubject(ctx context.Context, k Kind, jwtSubject string) (internal.Subject, error)

func (*Service) Middleware added in v0.2.2

func (a *Service) Middleware() mux.MiddlewareFunc

Middleware returns middleware for authenticating tokens

func (Service) NewSessionToken added in v0.2.2

func (f Service) NewSessionToken(username string, expiry time.Time) (string, error)

func (Service) NewToken added in v0.2.2

func (f Service) NewToken(opts NewTokenOptions) ([]byte, error)

func (Service) RegisterKind added in v0.2.2

func (r Service) RegisterKind(k Kind, fn SubjectGetter)

RegisterKind registers a kind of authentication token, providing a func that can retrieve the OTF subject indicated in the token.

func (Service) RegisterSiteToken added in v0.2.2

func (r Service) RegisterSiteToken(token string, siteAdmin internal.Subject)

RegisterSiteToken registers a site token which the middleware, and the subject to return as the site admin upon successful authentication.

func (Service) RegisterUISubjectGetterOrCreator added in v0.2.2

func (r Service) RegisterUISubjectGetterOrCreator(fn UISubjectGetterOrCreator)

func (*Service) StartSession added in v0.2.2

func (a *Service) StartSession(w http.ResponseWriter, r *http.Request, opts StartSessionOptions) error

type StartSessionOptions

type StartSessionOptions struct {
	Username *string
	Expiry   *time.Time
}

type SubjectGetter added in v0.2.0

type SubjectGetter func(ctx context.Context, jwtSubject string) (internal.Subject, error)

SubjectGetter retrieves an OTF subject given the jwtSubject string, which is the value of the 'subject' field parsed from a JWT.

type UISubjectGetterOrCreator added in v0.2.0

type UISubjectGetterOrCreator func(ctx context.Context, login string) (internal.Subject, error)

UISubjectGetterOrCreator retrieves the OTF subject with the given login that is attempting to access the UI. If the subject does not exist it is created.

Jump to

Keyboard shortcuts

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