jwtToken

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Copyright (c) 2020 Steven Victor https://github.com/tienbm90/simple-jwt-auth/blob/master/LICENSE

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken = errors.New("token is invalid")
	ErrExpiredToken = errors.New("token has expired")
)

Functions

func ExtractToken

func ExtractToken(r *http.Request) string

get the token from the request body

func TokenValid

func TokenValid(r *http.Request, secretKey string) error

func VerifyToken

func VerifyToken(r *http.Request, secretKey string) (*jwt.Token, error)

Types

type AccessDetails

type AccessDetails struct {
	TokenUuid string
	UserId    string
	UserName  string
}

func Extract

func Extract(token *jwt.Token) (*AccessDetails, error)

Extract 抽出

func ExtractTokenMetadata

func ExtractTokenMetadata(r *http.Request, secretKey string) (*AccessDetails, error)

ExtractTokenMetadata トークンのメタデータを抽出

type JWTMaker

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

JWTMaker is a JSON Web Token maker

func (*JWTMaker) CreateToken

func (maker *JWTMaker) CreateToken(username string, duration time.Duration) (string, error)

CreateToken creates a new token for a specific username and duration

func (*JWTMaker) VerifyToken

func (maker *JWTMaker) VerifyToken(token string) (*Payload, error)

VerifyToken checks if the token is valid or not

type Maker

type Maker interface {
	CreateToken(username string, duration time.Duration) (string, error)
	VerifyToken(token string) (*Payload, error)
}

func NewJWTMaker

func NewJWTMaker(secretKey string) (Maker, error)

NewJWTMaker creates a new JWTMaker

type Payload

type Payload struct {
	ID        uuid.UUID `json:"id"`
	Username  string    `json:"username"`
	IssuedAt  time.Time `json:"issued_at"`
	ExpiredAt time.Time `json:"expired_at"`
}

func NewPayload

func NewPayload(username string, duration time.Duration) (*Payload, error)

func (*Payload) Valid

func (payload *Payload) Valid() error

type TokenDetails

type TokenDetails struct {
	AccessToken  string
	RefreshToken string
	TokenUuid    string
	RefreshUuid  string
	AtExpires    int64
	RtExpires    int64
}

func CreateToken

func CreateToken(userID, userName, secretKey, refreshKey string) (*TokenDetails, error)

func NewTokenDetails

func NewTokenDetails() *TokenDetails

Jump to

Keyboard shortcuts

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