jwt

package
v2.0.0-...-571da87 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextExtractor

type ContextExtractor func(ctx context.Context) (string, error)

ContextExtractor is a helper function used to extract values from context Sometimes it's convenient to have Authorization header within the context, i.e GRPC-Gateway Implementation of this function should treat that use case

type ExtractorBuilder

type ExtractorBuilder interface {
	// What decoder to use when unmarshalling
	SetDecoder(dec JSONDecoder) ExtractorBuilder
	// ContextExtractor lets you set a custom extractor from context.Context
	SetContextExtractor(extractor ContextExtractor) ExtractorBuilder
	// SetBase64Decoder lets you customize base64.Encoding, standard or URL or other
	SetBase64Decoder(dec *base64.Encoding) ExtractorBuilder
	Build() TokenExtractor
}

ExtractorBuilder lets you define custom options

type JSONDecoder

type JSONDecoder func(data []byte, v interface{}) error

JSONDecoder is an alias to json.Unmarshal

type Token

type Token interface {
	// Raw returns JWT token as is: Base64("<algo>.<payload>.<signature>")
	Raw() string
	// Payload returns the payload (middle part) of JWT after base64 decode: UnBase64("<payload>")
	Payload() []byte
	// Map extracts token values (it's a JSON) to a map
	Map() (map[string]interface{}, error)
	// Decode extracts token values to a specified struct, struct should be a pointer
	// 	{
	// 		Subject string `json:"sub"`
	// 		Issuer string `json:"iss"`
	//		...
	// 	}
	Decode(target interface{}) error
}

Token interface shouldn't be used as a standalone since it doesn't have anything to work on It's implementation must be created by the `Extractor` interface from above

type TokenExtractor

type TokenExtractor interface {
	// FromContext should try to extract a token from the Context using `ContextExtractor`
	FromContext(ctx context.Context) (Token, error)
	// FromString accepts a JWT token in form of a string
	//	xxxxx.yyyyy.zzzzz
	FromString(str string) (Token, error)
}

TokenExtractor is a public interface to help with token extraction or preparing

Directories

Path Synopsis
Package mock_jwt is a generated GoMock package.
Package mock_jwt is a generated GoMock package.

Jump to

Keyboard shortcuts

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