gin

package
v0.0.42 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromHeader

func FromHeader(ctx *gin.Context) string

FromHeader is a token extractor. It reads the token from the Authorization request header of form: Authorization: "Bearer {token}".

func FromQuery

func FromQuery(ctx *gin.Context) string

FromQuery is a token extractor. It reads the token from the "token" url query parameter.

func Get

func Get(ctx *gin.Context) *multi.MultiClaims

Get returns the claims decoded by a verifier.

func GetAuthorityId

func GetAuthorityId(ctx *gin.Context) []string

GetAuthorityId 角色id

func GetAuthorityType

func GetAuthorityType(ctx *gin.Context) int

GetAuthorityType 角色类型

func GetCreationDate

func GetCreationDate(ctx *gin.Context) int64

GetCreationDate 登录时间

func GetExpiresIn

func GetExpiresIn(ctx *gin.Context) int64

GetExpiresIn 有效期

func GetTenancyId

func GetTenancyId(ctx *gin.Context) uint

GetTenancyId 商户id

func GetTenancyName

func GetTenancyName(ctx *gin.Context) string

GetTenancyName 商户名称

func GetUserId

func GetUserId(ctx *gin.Context) uint

GetUserId 用户id

func GetUsername

func GetUsername(ctx *gin.Context) string

GetUsername 用户名

func GetVerifiedToken

func GetVerifiedToken(ctx *gin.Context) []byte

func IsAdmin

func IsAdmin(ctx *gin.Context) bool

func IsRole added in v0.0.4

func IsRole(ctx *gin.Context, authorityType int) bool

Types

type TokenExtractor

type TokenExtractor func(*gin.Context) string

TokenExtractor is a function that takes a context as input and returns a token. An empty string should be returned if no token found without additional information.

func FromJSON

func FromJSON(jsonKey string) TokenExtractor

FromJSON is a token extractor. Reads a json request body and extracts the json based on the given field. The request content-type should contain the: application/json header value, otherwise this method will not try to read and consume the body.

type Verifier

type Verifier struct {
	Extractors   []TokenExtractor
	Validators   []multi.TokenValidator
	ErrorHandler func(ctx *gin.Context, err error)
}

func NewVerifier

func NewVerifier(validators ...multi.TokenValidator) *Verifier

func (*Verifier) RequestToken

func (v *Verifier) RequestToken(ctx *gin.Context) (token string)

RequestToken extracts the token from the

func (*Verifier) Verify

func (v *Verifier) Verify(validators ...multi.TokenValidator) gin.HandlerFunc

func (*Verifier) VerifyToken

func (v *Verifier) VerifyToken(token []byte, validators ...multi.TokenValidator) ([]byte, *multi.MultiClaims, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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