Browse Source

代码调整

terry 2 years ago
parent
commit
5fc1bcc490

+ 0 - 1
app/device/dao/common.go

@@ -2,7 +2,6 @@ package dao
 
 import (
 	"fmt"
-	_ "github.com/go-sql-driver/mysql"
 	"github.com/jinzhu/gorm"
 	"iot_manager_service/app/system/dao"
 )

+ 4 - 3
app/middleware/token.go

@@ -2,13 +2,14 @@ package middleware
 
 import (
 	"github.com/golang-jwt/jwt"
-	"iot_manager_service/app/system/model"
 	"iot_manager_service/config"
 	"time"
 )
 
 const (
 	Authorization = "Authorization"
+	Audience      = "audience"
+	Issuer        = "issuser"
 )
 
 var EmptyKeyFunc = func(t *jwt.Token) (interface{}, error) { return []byte(config.Instance().Server.TokenSign), nil }
@@ -24,8 +25,8 @@ type Claims struct {
 
 func GetAccessToken(userId, roleId int64, tenantId int, userName string, random string) (string, error) {
 	jwtToken := Claims{StandardClaims: jwt.StandardClaims{
-		Audience:  model.Audience,
-		Issuer:    model.Issuer,
+		Audience:  Audience,
+		Issuer:    Issuer,
 		ExpiresAt: time.Now().Add(2 * time.Hour).Unix(),
 		NotBefore: time.Now().Unix(),
 	},

+ 2 - 2
app/system/controller/token.go

@@ -159,8 +159,8 @@ func checkLock() {
 
 func getRefreshToken(info model.UserInfo) string {
 	claims := jwt.NewWithClaims(jwt.SigningMethodHS512, jwt.MapClaims{
-		model.Iss:       model.Issuer,
-		model.Aud:       model.Audience,
+		model.Iss:       middleware.Issuer,
+		model.Aud:       middleware.Audience,
 		model.ClientId:  model.Saber,
 		model.TokenType: model.RefreshToken,
 		model.UserId:    info.ID,

+ 0 - 1
app/system/dao/common.go

@@ -2,7 +2,6 @@ package dao
 
 import (
 	"fmt"
-	_ "github.com/go-sql-driver/mysql"
 	"github.com/jinzhu/gorm"
 )
 

+ 0 - 2
app/system/model/token.go

@@ -67,8 +67,6 @@ const (
 	Nbf       = "nbf"
 	BEARER    = "bearer"
 
-	Audience     = "audience"
-	Issuer       = "issuser"
 	AccessToken  = "access_token"
 	RefreshToken = "refresh_token"
 	Saber        = "saber"

+ 1 - 0
main.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"github.com/gin-gonic/gin"
+	_ "github.com/go-sql-driver/mysql"
 	"github.com/jinzhu/gorm"
 	device "iot_manager_service/app/device/dao"
 	system "iot_manager_service/app/system/dao"