web

package
v0.0.0-...-cbbd1a2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractToken

func ExtractToken(r *http.Request) string

func VerifiedJwtToken

func VerifiedJwtToken(r *http.Request, secretKey []byte) (*jwt.Token, error)

func WaitForHttpServer

func WaitForHttpServer(baseUrl string, timeout time.Duration) error

Types

type AuthenticatorT

type AuthenticatorT = func(*http.Request) (bool, *jwt.Token, error)

func AuthenticatorC

func AuthenticatorC(
	secretKey []byte,
) AuthenticatorT

AuthenticatorC constructs an AuthenticatorT function from the secretKey argument. The constructed authenticator only uses the JWT token signature and expiration to authenticate. A more elaborate authenticator could use a cache to enable immediate token invalidation in case of logout.

type ErrorDetail

type ErrorDetail struct {
	Err  string
	Args []string
	Path string
}

type ErrorResult

type ErrorResult struct {
	StatusCode       int
	StatusPhrase     string
	DeveloperMessage string
	ErrorString      string
	TraceId          string
	ParentSpanId     string
	SpanId           string
	Cause            map[string]string
	Args             []any
	Details          []ErrorDetail
}

func DefaultErrorHandler

func DefaultErrorHandler(errorContents any, ctx RequestContext) ErrorResult

type RequestContext

type RequestContext struct {
	Username string
	Token    *jwt.Token
}

func DefaultReqCtxExtractor

func DefaultReqCtxExtractor(_ *http.Request, token *jwt.Token) (RequestContext, error)

DefaultReqCtxExtractor returns a RequestContext based on token if token is not nil, returns a zero RequestToken otherwise. It never returns an error.

type TokenDetails

type TokenDetails struct {
	AccessToken  *jwt.Token
	RefreshToken *jwt.Token
	AccessUuid   string
	RefreshUuid  string
}

func CreateToken

func CreateToken(
	userid string,
	secretKey []byte,
	accessMinutes int,
	refreshHours int,
) (*TokenDetails, error)

func (TokenDetails) AccessClaims

func (s TokenDetails) AccessClaims() jwt.MapClaims

func (TokenDetails) AccessExp

func (s TokenDetails) AccessExp() int64

func (TokenDetails) RefreshClaims

func (s TokenDetails) RefreshClaims() jwt.MapClaims

func (TokenDetails) RefreshExp

func (s TokenDetails) RefreshExp() int64

func (TokenDetails) Sub

func (s TokenDetails) Sub() string

Directories

Path Synopsis
eg

Jump to

Keyboard shortcuts

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