| | |
| | | package middleware |
| | | |
| | | import ( |
| | | "aps_crm/conf" |
| | | "aps_crm/model" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/pkg/logx" |
| | | "aps_crm/service" |
| | | "aps_crm/utils" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | "strings" |
| | | "time" |
| | | ) |
| | | |
| | | var jwtService = service.ServiceGroup.JwtService |
| | |
| | | // response.FailWithDetailed(gin.H{"reload": true}, err.Error(), c) |
| | | // c.Abort() |
| | | //} |
| | | //if claims.ExpiresAt-time.Now().Unix() < claims.BufferTime { |
| | | // dr, _ := utils.ParseDuration(conf.Conf.JWT.ExpiresTime) |
| | | // claims.ExpiresAt = time.Now().Add(dr).Unix() |
| | | // newToken, _ := j.CreateTokenByOldToken(token, *claims) |
| | | // newClaims, _ := j.ParseToken(newToken) |
| | | // c.Header("new-token", newToken) |
| | | // c.Header("new-expires-at", strconv.FormatInt(newClaims.ExpiresAt, 10)) |
| | | // if conf.Conf.System.UseMultipoint { |
| | | // RedisJwtToken, err := jwtService.GetRedisJWT(newClaims.Username) |
| | | // if err != nil { |
| | | // logx.Errorf("get redis jwt failed err:%v", err) |
| | | // } else { // 当之前的取成功时才进行拉黑操作 |
| | | // _ = jwtService.JsonInBlacklist(model.JwtBlacklist{Jwt: RedisJwtToken}) |
| | | // } |
| | | // // 无论如何都要记录当前的活跃状态 |
| | | // _ = jwtService.SetRedisJWT(newToken, newClaims.Username) |
| | | // } |
| | | //} |
| | | if claims.ExpiresAt-time.Now().Unix() < claims.BufferTime { |
| | | dr, _ := utils.ParseDuration(conf.Conf.JWT.ExpiresTime) |
| | | claims.ExpiresAt = time.Now().Add(dr).Unix() |
| | | newToken, _ := j.CreateTokenByOldToken(token, *claims) |
| | | newClaims, _ := j.ParseToken(newToken) |
| | | c.Header("new-token", newToken) |
| | | c.Header("new-expires-at", strconv.FormatInt(newClaims.ExpiresAt, 10)) |
| | | if conf.Conf.System.UseMultipoint { |
| | | RedisJwtToken, err := jwtService.GetRedisJWT(newClaims.Username) |
| | | if err != nil { |
| | | logx.Errorf("get redis jwt failed err:%v", err) |
| | | } else { // 当之前的取成功时才进行拉黑操作 |
| | | _ = jwtService.JsonInBlacklist(model.JwtBlacklist{Jwt: RedisJwtToken}) |
| | | } |
| | | // 无论如何都要记录当前的活跃状态 |
| | | _ = jwtService.SetRedisJWT(newToken, newClaims.Username) |
| | | } |
| | | } |
| | | c.Set("claims", claims) |
| | | c.Next() |
| | | } |