fix jwt bug
This commit is contained in:
parent
d05ff71755
commit
415490a98d
4 changed files with 106 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/yaoapp/xiang/user"
|
"github.com/yaoapp/xiang/user"
|
||||||
|
"github.com/yaoapp/xiang/xlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Guards 服务中间件
|
// Guards 服务中间件
|
||||||
|
|
@ -24,11 +25,15 @@ func bearerJWT(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
||||||
|
if Conf.Mode == "debug" {
|
||||||
|
xlog.Printf("JWT: %s Secret: %s", tokenString, Conf.JWT.Secret)
|
||||||
|
}
|
||||||
token, err := jwt.ParseWithClaims(tokenString, &user.JwtClaims{}, func(token *jwt.Token) (interface{}, error) {
|
token, err := jwt.ParseWithClaims(tokenString, &user.JwtClaims{}, func(token *jwt.Token) (interface{}, error) {
|
||||||
return Conf.JWT.Secret, nil
|
return []byte(Conf.JWT.Secret), nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
xlog.Printf("JWT ParseWithClaims Error: %s", err)
|
||||||
c.JSON(403, gin.H{"code": 403, "message": fmt.Sprintf("登录已过期或令牌失效(%s)", err)})
|
c.JSON(403, gin.H{"code": 403, "message": fmt.Sprintf("登录已过期或令牌失效(%s)", err)})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ func MakeToken(row maps.Map, ExpiresAt int64) string {
|
||||||
Type: row.Get("type").(string),
|
Type: row.Get("type").(string),
|
||||||
Name: row.Get("name").(string),
|
Name: row.Get("name").(string),
|
||||||
StandardClaims: jwt.StandardClaims{
|
StandardClaims: jwt.StandardClaims{
|
||||||
|
Id: fmt.Sprintf("%s_%d", row.Get("type"), row.Get("id")),
|
||||||
Subject: fmt.Sprintf("%d", row.Get("id")),
|
Subject: fmt.Sprintf("%d", row.Get("id")),
|
||||||
ExpiresAt: ExpiresAt,
|
ExpiresAt: ExpiresAt,
|
||||||
Issuer: fmt.Sprintf("%d", row.Get("id")),
|
Issuer: fmt.Sprintf("%d", row.Get("id")),
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@
|
||||||
"index": true
|
"index": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"label": "状态",
|
||||||
"name": "status",
|
"name": "status",
|
||||||
"type": "enum",
|
"type": "enum",
|
||||||
"default": "enabled",
|
"default": "enabled",
|
||||||
|
|
|
||||||
98
xiang/tables/menu.json
Normal file
98
xiang/tables/menu.json
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
{
|
||||||
|
"name": "菜单",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"decription": "象传菜单",
|
||||||
|
"bind": {
|
||||||
|
"model": "xiang.menu"
|
||||||
|
},
|
||||||
|
"apis": {
|
||||||
|
"search": {
|
||||||
|
"process": "models.xiang.menu.Paginate",
|
||||||
|
"guard": "-",
|
||||||
|
"default": [
|
||||||
|
{
|
||||||
|
"withs": {
|
||||||
|
"children": {
|
||||||
|
"query": {
|
||||||
|
"select": ["name", "id"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"wheres": [{ "column": "parent", "op": "null" }]
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
15
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"columns": {},
|
||||||
|
"filters": {},
|
||||||
|
"list": {
|
||||||
|
"primary": "id",
|
||||||
|
"layout": {
|
||||||
|
"columns": [
|
||||||
|
{ "name": "名称", "width": 6 },
|
||||||
|
{ "name": "父节点", "width": 6 },
|
||||||
|
{ "name": "图标", "width": 6 },
|
||||||
|
{ "name": "状态", "width": 6 },
|
||||||
|
{ "name": "路由", "width": 6 },
|
||||||
|
{ "name": "排列", "width": 4 },
|
||||||
|
{ "name": "block布局", "width": 4 },
|
||||||
|
{ "name": "显示", "width": 4 }
|
||||||
|
],
|
||||||
|
"filters": [{ "name": "名称", "width": 6 }]
|
||||||
|
},
|
||||||
|
"actions": {
|
||||||
|
"create": {
|
||||||
|
"type": "button",
|
||||||
|
"props": {
|
||||||
|
"label": "新建菜单",
|
||||||
|
"icon": "fas fa-plus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"view": {},
|
||||||
|
"edit": {},
|
||||||
|
"import": {},
|
||||||
|
"update": {},
|
||||||
|
"delete": {},
|
||||||
|
"insert": {},
|
||||||
|
"updateWhere": {},
|
||||||
|
"deleteWhere": {},
|
||||||
|
"updateSelect": {},
|
||||||
|
"deleteSelect": {},
|
||||||
|
"pagination": {},
|
||||||
|
"setting": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"edit": {
|
||||||
|
"primary": "id",
|
||||||
|
"layout": {
|
||||||
|
"fieldset": [
|
||||||
|
{
|
||||||
|
"title": "基础信息",
|
||||||
|
"description": "",
|
||||||
|
"columns": [
|
||||||
|
{ "name": "名称", "width": 6 },
|
||||||
|
{ "name": "图标", "width": 6 },
|
||||||
|
{ "name": "路由", "width": 6 },
|
||||||
|
{ "name": "排列", "width": 6 },
|
||||||
|
{ "name": "block布局", "width": 6 },
|
||||||
|
{ "name": "显示", "width": 6 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"actions": {
|
||||||
|
"cancel": {},
|
||||||
|
"save": {
|
||||||
|
"type": "button",
|
||||||
|
"props": {
|
||||||
|
"label": "保存"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"insert": {},
|
||||||
|
"view": {}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue