base

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TokenFromRequest

func TokenFromRequest(w http.ResponseWriter, r *http.Request) (string, error)

Types

type SharedJwtAuth

type SharedJwtAuth struct {
	// Required function takes the ID above and returns a (ViewerContext, error) tuple. Called by AuthFromViewer method to return the ViewerContext
	// to be used for the current request
	VCFromID func(string) (viewer.ViewerContext, error)

	// Required. Used to sign the token used to auth the user
	SigningKey interface{}

	// Length of time the access token should be valid for. Default is DefaultDuration
	Duration time.Duration

	// What algorithm method should be used to sign this token. Default is DefaultSigningMethod
	SigningMethod jwt.SigningMethod

	// ClaimFunc is used to return a new instance of jwt.Claims to be used instead of jwt.MapClaims
	// when generating token. It's passed to jwt.NewWithClaims
	ClaimFunc func(string) entjwt.Claims
	// This pairs well with ClaimFunc to generate a new empty claims instance which is passed to jwt.ParseWithClaims
	BaseClaimFunc func() entjwt.Claims

	// ExtendTokenDuration defines the window for which the token can be extended
	// (with a valid existing token and without a refresh token)
	// If not set (default), token can be extended whenever e.g. sliding window every 10 minutes, every request, etc.
	// If set, token can only be extended within that window e.g. if set to 5 minutes, will be 5 minutes
	// before token expires
	// By default, auth handler doesn't do anything and since DefaultDuration is currently 1 hour,
	// developer needs to pick *something* to do to extend tokens or provide a
	// longer duration
	ExtendTokenDuration time.Duration
}

SharedJwtAuth is shared code for authenticating the viewer from the given ID using JWT This is hidden in an internal package for now because AuthFromID() shouldn't be a public API since it exists to share code between similar implementations using jwt

func (*SharedJwtAuth) AuthFromID

func (auth *SharedJwtAuth) AuthFromID(viewerID string) (*entjwt.AuthedIdentity, error)

AuthFromID returns an AuthedIdentity that's shared across different implementation details of auth

func (*SharedJwtAuth) AuthViewer

AuthViewer takes the authorization token from the request and verifies if valid and then returns a ViewerContext which maps to user encoded in the token

func (*SharedJwtAuth) ExtendTokenExpiration

func (auth *SharedJwtAuth) ExtendTokenExpiration(tokenStr string) (string, error)

ExtendTokenExpiration takes the current token and gets a new auth token for the user See ExtendTokenDuration for more information

func (*SharedJwtAuth) GetBaseClaims

func (auth *SharedJwtAuth) GetBaseClaims() jwt.Claims

func (*SharedJwtAuth) ViewerFromToken

func (auth *SharedJwtAuth) ViewerFromToken(tokenStr string) (viewer.ViewerContext, error)

ViewerFromToken takes the token string and verifies if valid and then returns a ViewerContext which maps to user encoded in the token

Jump to

Keyboard shortcuts

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