jwt

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(token string) (josejwt.Claims, error)

Decode parse a string token, but don't validate it.

func Sign

func Sign(claims josejwt.Claims, method josecrypto.SigningMethod, key interface{}) (string, error)

Sign creates a JWT token with the given claims, signing method and key.

func StrToKeys added in v1.5.2

func StrToKeys(keys ...string) (res []interface{})

StrToKeys converts string slice to keys slice.

func Verify

func Verify(token josejwt.JWT, method josecrypto.SigningMethod, keys []interface{}, v ...*josejwt.Validator) (claims josejwt.Claims, err error)

Verify parse a string token and validate it with keys, signingMethods in rotationally.

Types

type JWT

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

JWT represents a module. it can be use to create, decode or verify JWT token.

func New

func New(keys ...interface{}) *JWT

New returns a JWT instance. if key omit, jwt will use crypto.Unsecured as signing method. Otherwise crypto.SigningMethodHS256 will be used. You can change it by jwt.SetMethods.

func (*JWT) Decode

func (j *JWT) Decode(token string) (josejwt.Claims, error)

Decode parse a string token, but don't validate it.

func (*JWT) GetExpiresIn

func (j *JWT) GetExpiresIn() time.Duration

GetExpiresIn returns jwt's expiration.

func (*JWT) SetAudience added in v1.5.4

func (j *JWT) SetAudience(audience ...string)

SetAudience sets claim "aud" per its type in https://tools.ietf.org/html/rfc7519#section-4.1.3

func (*JWT) SetBackupSigning added in v1.6.0

func (j *JWT) SetBackupSigning(method josecrypto.SigningMethod, keys ...interface{})

SetBackupSigning add a backup signing for Verify method, not for Sign method.

func (*JWT) SetExpiresIn

func (j *JWT) SetExpiresIn(expiresIn time.Duration)

SetExpiresIn set a expire duration to jwt. Default to 0, no "exp" will be added.

func (*JWT) SetIssuer

func (j *JWT) SetIssuer(issuer string)

SetIssuer set a issuer to jwt. Default to "", no "iss" will be added.

func (*JWT) SetKeys

func (j *JWT) SetKeys(keys ...interface{})

SetKeys set new keys to jwt. [deprecated] Please use SetSigning method.

func (*JWT) SetMethods

func (j *JWT) SetMethods(method josecrypto.SigningMethod)

SetMethods set one or more signing methods which can be used rotational. [deprecated] Please use SetSigning method.

func (*JWT) SetSigning added in v1.6.0

func (j *JWT) SetSigning(method josecrypto.SigningMethod, keys ...interface{})

SetSigning add signing method and keys.

func (*JWT) SetValidator

func (j *JWT) SetValidator(validator *josejwt.Validator)

SetValidator set a custom jwt.Validator to jwt. Default to nil.

func (*JWT) Sign

func (j *JWT) Sign(content map[string]interface{}, expiresIn ...time.Duration) (string, error)

Sign creates a JWT token with the given content and optional expiresIn.

token1, err1 := jwt.Sign(map[string]interface{}{"UserId": "xxxxx"})
// or
claims := josejwt.Claims{} // or claims := josejws.Claims{}
claims.Set("hello", "world")
token2, err2 := jwt.Sign(claims)

if expiresIn <= 0, expiration will not be set to claims:

token1, err1 := jwt.Sign(map[string]interface{}{"UserId": "xxxxx"}, time.Duration(0))

func (*JWT) Verify

func (j *JWT) Verify(token string) (claims josejwt.Claims, err error)

Verify parse a string token and validate it with keys, signingMethods and validator in rotationally.

type KeyPair

type KeyPair struct {
	PrivateKey interface{}
	PublicKey  interface{}
}

KeyPair represents key struct for ECDSA, RS/PS SigningMethod.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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