token

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JWT_SECRET         = "jwt_secret"
	JWT_REFRESH_SECRET = "jwt_refresh_secret"
)

Variables

View Source
var (
	// ErrMissingHeader means the `Authorization` header was empty.
	ErrMissingHeader = errors.New("the length of the `Authorization` header is zero")
)

Functions

func RefreshFromRequest

func RefreshFromRequest(c *gin.Context) (neoSignToken, neoRefreshToken string, err error)

func Sign

func Sign(ctx Context) (tokenString, refreshToken string, err error)

func SignRefreshToken

func SignRefreshToken(ctx Context) (tokenString string, err error)

func SignToken

func SignToken(ctx Context) (tokenString string, err error)

Types

type Context

type Context struct {
	UserID   uint64
	Username string
	Uuid     string
	Email    string
	IsAdmin  uint64
}

Context is the context of the JSON web token.

func Parse

func Parse(tokenString string, secret string, skipValidation bool) (*Context, error)

Parse validates the token with the specified secret, and returns the context if the token was valid.

func ParseRequest

func ParseRequest(c *gin.Context) (*Context, error)

ParseRequest gets the token from the header and pass it to the Parse function to parses the token.

Jump to

Keyboard shortcuts

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