jojo

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package jojo implements session interfaces for jwt tokens for long-season application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWT

type JWT struct {
	// Secret is jwt secret. The longer secret is, the better.
	Secret []byte

	// Algorithm is JWT algorithm used for signing
	Algorithm jwt.Algorithm

	// AppName is issuer application name.
	AppName string

	// CookieKey is key used to store API token in cookies.
	CookieKey string
}

JWT implements session's interfaces for stateless session management.

func (*JWT) Kill

func (j *JWT) Kill(_ context.Context, w http.ResponseWriter) error

Kill is method for purging JWT session by setting http cookie max age to -1.

func (*JWT) RenewFromCookies

func (j *JWT) RenewFromCookies() RenewStrategy

RenewFromCookies returns Renewer for retrieving session from http cookies.

func (*JWT) RenewFromHeaderToken

func (j *JWT) RenewFromHeaderToken(header, prefix string) RenewStrategy

RenewFromHeaderToken returns Renewer for retrieving session from given header with given prefix. For example for header equal to "Authorization" and prefix equal to "Bearer" returned RenewStrategy will retrieve JWT token from "Authorization" header in the form of "Bearer $TOKEN" where "$TOKEN" is tokenized JWT session State.

func (*JWT) Save

func (j *JWT) Save(ctx context.Context, w http.ResponseWriter, s session.State) error

Save is method for returning session data or session identifier to client.

func (*JWT) Tokenize

func (j *JWT) Tokenize(ctx context.Context, s session.State) (string, error)

Tokenize outputs JWT token representation of given state.

type RenewStrategy

type RenewStrategy func(*http.Request) (*session.State, error)

RenewStrategy is functional implementation of session's Renewer interface.

func (RenewStrategy) Renew

func (f RenewStrategy) Renew(r *http.Request) (*session.State, error)

Renew is method for restoring session from provided request data from client.

Jump to

Keyboard shortcuts

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