|
@@ -10,6 +10,8 @@ import (
|
10
|
10
|
|
11
|
11
|
const (
|
12
|
12
|
CtxRequestHeaderUserId = "user_id"
|
|
13
|
+ CtxRequestHeaderTeamId = "team_id"
|
|
14
|
+ CtxRequestHeaderRoleId = "role_id"
|
13
|
15
|
ctxRequestHeaderAuthorization = "Authorization"
|
14
|
16
|
ctxRequestCookieAuthorization = "ak"
|
15
|
17
|
ctxRequestTokenExpired = "expired"
|
|
@@ -58,6 +60,20 @@ func Auth(authKey string, session Session) gin.HandlerFunc {
|
58
|
60
|
ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, mapClaims[CtxRequestHeaderUserId].(float64) error"})
|
59
|
61
|
return
|
60
|
62
|
}
|
|
63
|
+
|
|
64
|
+ if tid, ok := mapClaims[CtxRequestHeaderTeamId].(float64); ok {
|
|
65
|
+ ctx.Set(CtxRequestHeaderTeamId, int64(tid))
|
|
66
|
+ } else {
|
|
67
|
+ ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, mapClaims[CtxRequestHeaderTeamId].(float64) error"})
|
|
68
|
+ return
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ if rid, ok := mapClaims[CtxRequestHeaderRoleId].(float64); ok {
|
|
72
|
+ ctx.Set(CtxRequestHeaderRoleId, int64(rid))
|
|
73
|
+ } else {
|
|
74
|
+ ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, mapClaims[CtxRequestHeaderRoleId].(float64) error"})
|
|
75
|
+ return
|
|
76
|
+ }
|
61
|
77
|
} else {
|
62
|
78
|
ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, token.Claims.(jwt.MapClaims) error"})
|
63
|
79
|
return
|