jwt

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: Apache-2.0 Imports: 28 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// DefaultNotBefore offset for NotBefore
	DefaultNotBefore = -2 * time.Minute
)

Variables

This section is empty.

Functions

func EncodeSegment

func EncodeSegment(seg []byte) string

EncodeSegment returns JWT specific base64url encoding with padding stripped

Types

type Claims

type Claims jwt.MapClaims

Claims provides generic claims on map

func (Claims) Add

func (c Claims) Add(val ...interface{}) error

Add new claims to the map

func (Claims) Bool

func (c Claims) Bool(k string) bool

Bool will return the named claim as Bool

func (Claims) Int

func (c Claims) Int(k string) int

Int will return the named claim as an int

func (Claims) Marshal

func (c Claims) Marshal() string

Marshal returns JSON encoded string

func (Claims) String

func (c Claims) String(k string) string

String will return the named claim as a string, if the underlying type is not a string, it will try and co-oerce it to a string.

func (Claims) Time

func (c Claims) Time(k string) *time.Time

Time will return the named claim as Time

func (Claims) To

func (c Claims) To(val interface{}) error

To converts the claims to the value pointed to by v.

func (Claims) Valid

func (c Claims) Valid() error

Valid returns error if the standard claims are invalid

type Config

type Config struct {
	// Issuer specifies issuer claim
	Issuer string `json:"issuer" yaml:"issuer"`
	// KeyID specifies ID of the current key
	KeyID string `json:"kid" yaml:"kid"`
	// Keys specifies list of issuer's keys
	Keys []*Key `json:"keys" yaml:"keys"`

	PrivateKey string `json:"private_key" yaml:"private_key"`
}

Config provides OAuth2 configuration

func LoadConfig

func LoadConfig(file string) (*Config, error)

LoadConfig returns configuration loaded from a file

type Key

type Key struct {
	// ID of the key
	ID   string `json:"id" yaml:"id"`
	Seed string `json:"seed" yaml:"seed"`
}

Key for JWT signature

type Option

type Option interface {
	// contains filtered or unexported methods
}

A Option modifies the default behavior of Provider.

func WithHeaders

func WithHeaders(headers map[string]interface{}) Option

WithHeaders allows to specify extra headers or override defaults

type Parser

type Parser interface {
	// ParseToken returns jwt.StandardClaims
	ParseToken(authorization string, cfg *VerifyConfig) (Claims, error)
}

Parser specifies JWT parser interface

type Provider

type Provider interface {
	Signer
	Parser
}

Provider specifies JWT provider interface

func Load

func Load(cfgfile string, crypto *cryptoprov.Crypto) (Provider, error)

Load returns new provider

func MustNew

func MustNew(cfg *Config, crypto *cryptoprov.Crypto, ops ...Option) Provider

MustNew returns new provider

func New

func New(cfg *Config, crypto *cryptoprov.Crypto, ops ...Option) (Provider, error)

New returns new provider that supports, both Signer and Parser

func NewFromCryptoSigner

func NewFromCryptoSigner(signer crypto.Signer, ops ...Option) (Provider, error)

NewFromCryptoSigner returns new from Signer

type Signer

type Signer interface {
	// SignToken returns signed JWT token
	SignToken(id, subject string, audience []string, expiry time.Duration, extraClaims Claims) (string, Claims, error)
	// PublicKey is returned for assymetric signer
	PublicKey() crypto.PublicKey
}

Signer specifies JWT signer interface

type SignerInfo

type SignerInfo struct {
	// contains filtered or unexported fields
}

SignerInfo represents JWT signer

func NewSignerInfo

func NewSignerInfo(signer crypto.Signer) (*SignerInfo, error)

NewSignerInfo returns *SignerInfo

type VerifyConfig

type VerifyConfig struct {
	// ExpectedSubject validates the sub claim of a JWT matches this value
	ExpectedSubject string
	// ExpectedAudience validates that the aud claim of a JWT contains this value
	ExpectedAudience string
}

VerifyConfig expreses the possible options for validating a JWT

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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