12345678910111213141516171819202122232425262728293031323334353637383940 |
- package middleware
- import (
- "Medical_OAuth/common/middleware/handler"
- jwt "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth"
- "gogs.baozhida.cn/zoie/OAuth-core/sdk/config"
- "time"
- )
- // AuthInit jwt验证new
- func AuthInit() (*jwt.GinJWTMiddleware, error) {
- timeout := time.Hour
- if config.ApplicationConfig.Mode == "dev" {
- timeout = time.Duration(876010) * time.Hour
- } else {
- if config.JwtConfig.Timeout != 0 {
- timeout = time.Duration(config.JwtConfig.Timeout) * time.Second
- }
- }
- return jwt.New(&jwt.GinJWTMiddleware{
- Realm: "bzd oauth",
- Key: []byte(config.JwtConfig.Secret),
- Timeout: timeout,
- SendCookie: true,
- // token 最大刷新时间
- MaxRefresh: 2 * time.Hour,
- PayloadFunc: handler.PayloadFunc,
- IdentityHandler: handler.IdentityHandler,
- Authenticator: handler.Authenticator,
- Authorizator: handler.Authorizator,
- Unauthorized: handler.Unauthorized,
- TokenLookup: "header: Authorization, query: token, cookie: jwt",
- TokenHeadName: "Bearer",
- TimeFunc: time.Now,
- SaveNewestToken: handler.SaveNewestToken,
- GetNewestToken: handler.GetNewestToken,
- SetEnterDeptId: handler.SetEnterDeptId,
- })
- }
|