gin_middleware

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCheckAdmin

func WithCheckAdmin(rolenames ...string) optparams.Option[options]

WithCheckAdmin 校验是否是管理员用户,也就是aud是否必须包含其中的至少一个,如果不包含则不能通过

func WithCheckIP

func WithCheckIP() optparams.Option[options]

WithCheckIP 校验IP一致性

func WithCheckRole

func WithCheckRole(role ...string) optparams.Option[options]

WithCheckRole 校验拥有特定权限,如果未设置WithCheckAdmin则会生效,校验aud是否包含其中至少一个

func WithCheckSelf

func WithCheckSelf(finder SelfFinder) optparams.Option[options]

WithCheckSelf 校验资源是请求者自己的,和WithCheckRole优先级一样,如果未设置WithCheckAdmin则会生效,校验sub是否和finder找到的uid一致

Types

type AuthMiddlewareFactoryFunc

type AuthMiddlewareFactoryFunc func(opts ...optparams.Option[options]) gin.HandlerFunc

MiddlewareFactory 构造auth校验中间件的工厂函数 没有参数则只校验令牌是否可用 有WithCheckIP会校验负载中的IP字段是否存在且和当前的请求IP一致 有WithCheckSuperUser则会校验令牌的aud中是否有superuser 没有设置WithCheckSuperUser时如果有设置WithCheckRole则会校验令牌的aud中是否包含指定的role字段 没有设置WithCheckSuperUser时如果有设置WithCheckSelf则会校验令牌的sub是否和用户自己的id一致 当用户是superuser时则不看是否有role或者id是否一致统一通过

func AuthMiddlewareMaker

func AuthMiddlewareMaker(verifier jwthelper.UniversalJwtVerifier, signer jwthelper.UniversalJwtSigner, verifyfunc VerifyFunc) AuthMiddlewareFactoryFunc

AuthMiddlewareMaker 用于构造`AuthMiddlewareFactoryFunc`的函数 @Params verifier jwthelper.UniversalJwtVerifier 校验器 @Params signer jwthelper.UniversalJwtSigner 签名器,用于在有Refresh-Token时刷新token @Params verifyfunc VerifyFunc 具体的校验逻辑

type SelfFinder

type SelfFinder func(*gin.Context) (int64, error)

SelfFinder 找到用户id的函数

type VerifyFunc

type VerifyFunc func(verifier jwthelper.UniversalJwtVerifier, signer jwthelper.UniversalJwtSigner, token *jwt_pb.Token, ip string, aud []string, selfuid int64, admins ...string) (string, error)

Jump to

Keyboard shortcuts

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