|
@@ -3,6 +3,7 @@ package controller
|
|
|
import (
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/golang-jwt/jwt"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
|
|
|
"iot_manager_service/app/user/model"
|
|
@@ -53,21 +54,21 @@ func (c *auth) Token(ctx *gin.Context) {
|
|
|
ctx.JSON(http.StatusOK, util.NormalResponse(http.StatusBadRequest, e.Error(), nil))
|
|
|
}
|
|
|
ctx.JSON(http.StatusOK, model.RspToken{
|
|
|
- TenantId: "",
|
|
|
- UserId: "",
|
|
|
- DeptId: "",
|
|
|
- PostId: "",
|
|
|
- RoleId: "",
|
|
|
- OauthId: "",
|
|
|
- Account: "",
|
|
|
- UserName: "",
|
|
|
- NickName: "",
|
|
|
- RoleName: "",
|
|
|
- Avatar: "",
|
|
|
+ TenantId: userInfo.TenantId,
|
|
|
+ UserId: strconv.FormatInt(userInfo.ID, 64),
|
|
|
+ DeptId: userInfo.DeptId,
|
|
|
+ PostId: userInfo.PostId,
|
|
|
+ RoleId: userInfo.RoleId,
|
|
|
+ OauthId: userInfo.OauthId,
|
|
|
+ Account: userInfo.Account,
|
|
|
+ UserName: userInfo.Name,
|
|
|
+ NickName: userInfo.RealName,
|
|
|
+ RoleName: userInfo.Roles[0],
|
|
|
+ Avatar: userInfo.Avatar,
|
|
|
AccessToken: jwtToken,
|
|
|
- RefreshToken: "",
|
|
|
- TokenType: "",
|
|
|
- ExpiresIn: 0,
|
|
|
+ RefreshToken: getRefreshToken(*userInfo),
|
|
|
+ TokenType: model.BEARER,
|
|
|
+ ExpiresIn: 7200,
|
|
|
License: "",
|
|
|
})
|
|
|
}
|
|
@@ -81,6 +82,8 @@ func getAccessToken(info model.UserInfo) (string, error) {
|
|
|
claims := jwt.NewWithClaims(jwt.SigningMethodHS512, jwt.MapClaims{
|
|
|
model.Iss: "issuser",
|
|
|
model.Aud: "audience",
|
|
|
+ model.TokenType: "access_token",
|
|
|
+ model.ClientId: "saber",
|
|
|
model.TenantId: info.TenantId,
|
|
|
model.RoleId: info.RoleId,
|
|
|
model.RoleName: info.Roles[0],
|
|
@@ -91,25 +94,24 @@ func getAccessToken(info model.UserInfo) (string, error) {
|
|
|
model.Account: info.Account,
|
|
|
model.UserName: info.Account,
|
|
|
model.NickName: info.RealName,
|
|
|
- model.TokenType: "access_token",
|
|
|
- model.ClientId: "saber",
|
|
|
- model.Exp: time.Now().Add(7 * 24 * time.Hour).Unix(),
|
|
|
+ model.Exp: time.Now().Add(2 * time.Hour).Unix(),
|
|
|
model.Nbf: time.Now().Unix(),
|
|
|
})
|
|
|
return claims.SigningString()
|
|
|
}
|
|
|
|
|
|
-func getRefreshToken(info model.UserInfo) (string, error) {
|
|
|
+func getRefreshToken(info model.UserInfo) string {
|
|
|
claims := jwt.NewWithClaims(jwt.SigningMethodHS512, jwt.MapClaims{
|
|
|
model.Iss: "issuser",
|
|
|
model.Aud: "audience",
|
|
|
- model.UserId: info.ID,
|
|
|
model.ClientId: "saber",
|
|
|
model.TokenType: "refresh_token",
|
|
|
+ model.UserId: info.ID,
|
|
|
model.Exp: time.Now().Add(7 * 24 * time.Hour).Unix(),
|
|
|
model.Nbf: time.Now().Unix(),
|
|
|
})
|
|
|
- return claims.SigningString()
|
|
|
+ token, _ := claims.SigningString()
|
|
|
+ return token
|
|
|
}
|
|
|
|
|
|
func grant(token model.Token, ctx *gin.Context) (*model.UserInfo, *util.Errors) {
|