auth

package
v0.0.0-...-26e1b9e Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

README

Auth模块

Auth模块主要是通过调用登陆认证中心进行用户的认证。

使用示例:

import (
	"gitlab.yaoxinhd.net/datalake/cato/cato-svc/handler"
	"gitee.com/peyton1991/kuat/auth"
	"gitee.com/peyton1991/kuat/xgin"
)
func InitRouter(r *xgin.Server) {
	ypHdr := handler.NewYellowPageHdr()
	g.POST("/yellowPageLabel/queryYellowPageLabels", auth.Auth("zlist:yellowPage:common"), ypHdr.GetYellowPageLabels)
}

auth.Auth需要加入API接口的唯一标识符号identify(同时还需要在widek系统上进行配置)。

内部实现流程:

1.判断用户是否携带认证信息(jwt token RSA加密)。

2.解析jwt token,判断是否过期。如果过期返回code:401。

3.通过解析jwt token得到用户名,根据用户名查询本地缓存(应用缓存,使用bigcache实现)是否存在用户的权限信息。如果本地缓存不存在,则调用鉴权中心请求用户的权限信息,并在本地缓存中保留15分钟。

4.根据用户权限信息判断是否有权限访问本接口。如果有权限则放行,并且用户信息保留在请求上下文中。

Documentation

Index

Constants

View Source
const (
	UserKey = "username"
)

Variables

This section is empty.

Functions

func Auth

func Auth(identify string) gin.HandlerFunc

func Init

func Init(conf *Config)

func ParseToken

func ParseToken(tokenString string, key interface{}) (interface{}, bool)

ParseToken 解析token

Types

type Config

type Config struct {
	Url       string         `json:"url" yaml:"url"`             // 认证中心地址
	Cache     *memory.Config `json:"cache" yaml:"cache"`         //缓存配置
	PublicKey string         `json:"publicKey" yaml:"publicKey"` //公钥
}

Jump to

Keyboard shortcuts

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