auth

package
v0.0.0-...-8f419a9 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingJwtToken    = errors.Unauthorized(reason, "JWT token is missing")
	ErrTokenInvalid       = errors.Unauthorized(reason, "Token is invalid")
	ErrTokenExpired       = errors.Unauthorized(reason, "JWT token has expired")
	ErrTokenParseFail     = errors.Unauthorized(reason, "Fail to parse JWT token ")
	ErrWrongContext       = errors.Unauthorized(reason, "Wrong context for middleware")
	ErrorPermissionDenied = errors.Forbidden(reasonPermission, "Permission denied")
)

Functions

func GenerateToken

func GenerateToken(id uint64, name, key string) (string, error)

GenerateToken 生成token

func NewContext

func NewContext(ctx context.Context, info *JwtClaims) context.Context

NewContext put auth info into context

func Server

func Server(jwtSecret string) middleware.Middleware

Server is a server auth middleware. Check the token and extract the info from token.

Types

type JwtClaims

type JwtClaims struct {
	ID   uint64
	Name string
	jwt.RegisteredClaims
}

func FromContext

func FromContext(ctx context.Context) (token *JwtClaims, ok bool)

FromContext extract auth info from context

func ParseToken

func ParseToken(tokenString, key string) (*JwtClaims, error)

ParseToken 解析token

Jump to

Keyboard shortcuts

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