jwtauth

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSigningMethod = jwt.SigningMethodHS256

Functions

This section is empty.

Types

type Claims

type Claims struct {
	// The identity of this token, which can be any data that is json serializable.
	Identity interface{}

	// Every time a user authenticates by providing a username and password,
	// they receive a Fresh access token that can access any route.
	//
	// But after some time, that token should no longer be considered fresh,
	// and some critical or dangerous routes will be blocked until the user verifies their password again.
	Fresh bool

	// TokenType includes AccessTokenType and RefreshTokenType.
	TokenType TokenType

	jwt.RegisteredClaims
}

Claims is the custom claims type.

func (*Claims) HasExpired

func (c *Claims) HasExpired() bool

HasExpired returns true if the token has expired.

type JwtAuth

type JwtAuth struct {
	*Options
}

func New

func New(o *Options) *JwtAuth

New returns new JwtAuth.

func (*JwtAuth) CreateAccessToken

func (j *JwtAuth) CreateAccessToken(identity interface{}, fresh bool) (string, error)

CreateAccessToken create a new access token. The identity of this token, which can be any data that is json serializable.

func (*JwtAuth) CreateRefreshToken

func (j *JwtAuth) CreateRefreshToken(identity interface{}) (string, error)

CreateRefreshToken create a new refresh token. The identity of this token, which can be any data that is json serializable.

func (*JwtAuth) ParseJwtToken

func (j *JwtAuth) ParseJwtToken(tokenString string) (*Claims, error)

func (*JwtAuth) ParseToken

func (j *JwtAuth) ParseToken(tokenString string) (auth.Claims, error)

ParseToken parse token string to Claims.

type Options

type Options struct {
	JwtSecretKey           string
	JwtAccessTokenExpires  time.Duration
	JwtRefreshTokenExpires time.Duration
	JwtIssuer              string
	JwtSubject             string
	JwtAudience            []string
}

Options is a struct for specifying configuration options for the JWT.

func NewOptions

func NewOptions(v *viper.Viper) (*Options, error)

NewOptions returns a new instance of the options with the given parameters.

type TokenType

type TokenType int
const (
	AccessTokenType TokenType = iota + 1
	RefreshTokenType
)

Jump to

Keyboard shortcuts

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