jwt

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OfflineTokenScope is a scope value to request refresh token.
	OfflineTokenScope = "offline"
	// RefrestTokenType is a refresh token type value.
	RefrestTokenType = "refresh"
	// InviteTokenType is an invite token type value.
	InviteTokenType = "invite"
	// AccessTokenType is an access token type value.
	AccessTokenType = "access"
	// ResetTokenType is a reset password token type value.
	ResetTokenType = "reset"
	// WebCookieTokenType is a web-cookie token type value.
	WebCookieTokenType = "web-cookie"
)
View Source
const TokenHeaderKeyPrefix = "BEARER "

TokenHeaderKeyPrefix is a token prefix regarding RFCXXX.

Variables

View Source
var (
	// ErrWrongSignatureAlgorithm is for unsupported signature algorithm.
	ErrWrongSignatureAlgorithm = errors.New("Unsupported signature algorithm")
	// ErrEmptyToken is when token is empty.
	ErrEmptyToken = errors.New("Token is empty")
	// ErrTokenInvalid is when token is invalid.
	ErrTokenInvalid = errors.New("Token is invalid")
)

StrToTokenSignAlg maps string token service algorithm names to values.

View Source
var TimeFunc = time.Now

TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time). You can override it to use another time value. This is useful for testing or if your server uses a time zone different from your tokens'.

Functions

func ExtractTokenFromBearerHeader

func ExtractTokenFromBearerHeader(token string) []byte

ExtractTokenFromBearerHeader extracts token from the Bearer token header value.

func LoadPrivateKeyFromPEM

func LoadPrivateKeyFromPEM(file string, alg TokenSignatureAlgorithm) (interface{}, error)

LoadPrivateKeyFromPEM loads private key from PEM file.

func LoadPublicKeyFromPEM

func LoadPublicKeyFromPEM(file string, alg TokenSignatureAlgorithm) (interface{}, error)

LoadPublicKeyFromPEM loads public key from PEM file.

func LoadPublicKeyFromString

func LoadPublicKeyFromString(s string, alg TokenSignatureAlgorithm) (interface{}, error)

LoadPublicKeyFromString loads public key from string.

func NewTokenWithClaims

func NewTokenWithClaims(method jwt.SigningMethod, kid string, claims jwt.Claims) *jwt.Token

NewTokenWithClaims generates new JWT token with claims and keyID.

Types

type Claims

type Claims struct {
	Payload map[string]string `json:"payload,omitempty"`
	Scopes  string            `json:"scopes,omitempty"`
	Type    string            `json:"type,omitempty"`
	KeyID   string            `json:"kid,omitempty"` // optional keyID
	jwt.StandardClaims
}

Claims is an extended claims structure.

type JWToken

type JWToken struct {
	JWT *jwt.Token
	New bool
}

JWToken represents JWT token.

func (*JWToken) Payload

func (t *JWToken) Payload() map[string]string

Payload returns token payload.

func (*JWToken) Type

func (t *JWToken) Type() string

Type returns token type.

func (*JWToken) UserID

func (t *JWToken) UserID() string

UserID returns user ID.

func (*JWToken) Validate

func (t *JWToken) Validate() error

Validate validates token data. Returns nil if all data is valid.

type Token

type Token interface {
	Validate() error
	UserID() string
	Type() string
	Payload() map[string]string
}

Token is an abstract application token.

func ParseTokenWithPublicKey

func ParseTokenWithPublicKey(t string, publicKey interface{}) (Token, error)

ParseTokenWithPublicKey parses token with provided public key.

type TokenSignatureAlgorithm

type TokenSignatureAlgorithm int

TokenSignatureAlgorithm is a signing algorithm used by the token service. For now, we only support ES256 and RS256.

const (
	// TokenSignatureAlgorithmES256 is a ES256 signature.
	TokenSignatureAlgorithmES256 TokenSignatureAlgorithm = iota + 1
	// TokenSignatureAlgorithmRS256 is a RS256 signature.
	TokenSignatureAlgorithmRS256
	// TokenSignatureAlgorithmAuto tries to detect algorithm on the fly.
	TokenSignatureAlgorithmAuto
)

func LoadPublicKeyFromPEMAuto added in v0.0.10

func LoadPublicKeyFromPEMAuto(file string) (interface{}, TokenSignatureAlgorithm, error)

LoadPublicKeyFromPEMAuto loads keys from pem file with key algorithm auto detection

func LoadPublicKeyFromStringAuto added in v0.0.10

func LoadPublicKeyFromStringAuto(s string) (interface{}, TokenSignatureAlgorithm, error)

LoadPublicKeyFromStringAuto loads keys from string with key algorithm auto detection

func (TokenSignatureAlgorithm) MarshalJSON

func (alg TokenSignatureAlgorithm) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaller.

func (TokenSignatureAlgorithm) MarshalYAML

func (alg TokenSignatureAlgorithm) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaller.

func (TokenSignatureAlgorithm) String

func (alg TokenSignatureAlgorithm) String() string

String implements Stringer.

func (*TokenSignatureAlgorithm) UnmarshalJSON

func (alg *TokenSignatureAlgorithm) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaller.

func (*TokenSignatureAlgorithm) UnmarshalYAML

func (alg *TokenSignatureAlgorithm) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaller.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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