fix: update jwt version
This commit is contained in:
@@ -3,12 +3,12 @@ module message-nest
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/dgrijalva/jwt-go v3.1.0+incompatible
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/go-ini/ini v1.32.1-0.20180214101753-32e4be5f41bb
|
||||
github.com/go-playground/locales v0.14.1
|
||||
github.com/go-playground/universal-translator v0.18.1
|
||||
github.com/go-playground/validator/v10 v10.16.0
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0
|
||||
github.com/google/uuid v1.5.0
|
||||
github.com/jinzhu/gorm v0.0.0-20180213101209-6e1387b44c64
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
|
||||
@@ -14,8 +14,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20190920000552-128d9f4ae1cd h1:tXCgEGHPT4XELDS7nB0OBb9968yCOd+MnyNf+6m1u40=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20190920000552-128d9f4ae1cd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||
github.com/dgrijalva/jwt-go v3.1.0+incompatible h1:FFziAwDQQ2dz1XClWMkwvukur3evtZx7x/wMHKM1i20=
|
||||
github.com/dgrijalva/jwt-go v3.1.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
@@ -37,6 +35,8 @@ github.com/go-sql-driver/mysql v1.4.1-0.20190510102335-877a9775f068 h1:q2kwd9Bcg
|
||||
github.com/go-sql-driver/mysql v1.4.1-0.20190510102335-877a9775f068/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"message-nest/pkg/table"
|
||||
"message-nest/pkg/util"
|
||||
"message-nest/service/cron_service"
|
||||
"message-nest/service/env_service"
|
||||
"message-nest/service/send_message_service"
|
||||
@@ -30,7 +29,6 @@ func init() {
|
||||
setting.Setup()
|
||||
models.Setup()
|
||||
logging.Setup()
|
||||
util.Setup()
|
||||
table.Setup()
|
||||
env_service.Setup()
|
||||
cron_service.Setup()
|
||||
|
||||
+8
-3
@@ -1,7 +1,8 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"errors"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -35,8 +36,12 @@ func JWT() gin.HandlerFunc {
|
||||
} else {
|
||||
claims, err := util.ParseToken(token)
|
||||
if err != nil {
|
||||
switch err.(*jwt.ValidationError).Errors {
|
||||
case jwt.ValidationErrorExpired:
|
||||
switch {
|
||||
case errors.Is(err, jwt.ErrTokenMalformed):
|
||||
code = e.ERROR_AUTH
|
||||
case errors.Is(err, jwt.ErrTokenSignatureInvalid):
|
||||
code = e.ERROR_AUTH_CHECK_TOKEN_FAIL
|
||||
case errors.Is(err, jwt.ErrTokenExpired) || errors.Is(err, jwt.ErrTokenNotValidYet):
|
||||
code = e.ERROR_AUTH_CHECK_TOKEN_TIMEOUT
|
||||
default:
|
||||
code = e.ERROR_AUTH_CHECK_TOKEN_FAIL
|
||||
|
||||
+26
-29
@@ -1,50 +1,47 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"message-nest/pkg/setting"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
var jwtSecret []byte
|
||||
|
||||
type Claims struct {
|
||||
type UserClaims struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
jwt.StandardClaims
|
||||
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
// GenerateToken generate tokens used for auth
|
||||
func GenerateToken(username, password string) (string, error) {
|
||||
nowTime := time.Now()
|
||||
expireTime := nowTime.Add(1 * 24 * time.Hour)
|
||||
|
||||
claims := Claims{
|
||||
username,
|
||||
EncodeMD5(password),
|
||||
jwt.StandardClaims{
|
||||
ExpiresAt: expireTime.Unix(),
|
||||
expHours := 1 * 24 * time.Hour
|
||||
SetClaims := UserClaims{
|
||||
Username: username,
|
||||
Password: EncodeMD5(password),
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(expHours)),
|
||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||
NotBefore: jwt.NewNumericDate(time.Now()),
|
||||
Issuer: "message-nest",
|
||||
},
|
||||
}
|
||||
|
||||
tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
token, err := tokenClaims.SignedString(jwtSecret)
|
||||
|
||||
tokenStruct := jwt.NewWithClaims(jwt.SigningMethodHS256, SetClaims)
|
||||
token, err := tokenStruct.SignedString([]byte(setting.AppSetting.JwtSecret))
|
||||
return token, err
|
||||
}
|
||||
|
||||
// ParseToken parsing token
|
||||
func ParseToken(token string) (*Claims, error) {
|
||||
tokenClaims, err := jwt.ParseWithClaims(token, &Claims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return jwtSecret, nil
|
||||
func ParseToken(tokenString string) (*UserClaims, error) {
|
||||
tokenObj, err := jwt.ParseWithClaims(tokenString, &UserClaims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte(setting.AppSetting.JwtSecret), nil
|
||||
})
|
||||
|
||||
if tokenClaims != nil {
|
||||
if claims, ok := tokenClaims.Claims.(*Claims); ok && tokenClaims.Valid {
|
||||
return claims, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if claims, ok := tokenObj.Claims.(*UserClaims); ok && tokenObj.Valid {
|
||||
return claims, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalid token")
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"message-nest/pkg/setting"
|
||||
)
|
||||
|
||||
// Setup Initialize the util
|
||||
func Setup() {
|
||||
jwtSecret = []byte(setting.AppSetting.JwtSecret)
|
||||
}
|
||||
+1
-3
@@ -52,7 +52,7 @@ const CONSTANT = {
|
||||
label: '自定义',
|
||||
inputs: [
|
||||
{ subLabel: 'webhook地址', value: '', col: 'webhook', desc: "自定义webhook地址" },
|
||||
{ subLabel: '请求体', value: '', col: 'body', desc: "请求体, text内容请使用 TEXT 进行占位\n例如:{\"message\": \"TEXT\", \"other_field\": \"field_data\"}", isTextArea: true},
|
||||
{ subLabel: '请求体', value: '', col: 'body', desc: "请求体, text内容请使用 TEXT 进行占位\n例如:{\"message\": \"TEXT\", \"foo\": \"bar\"}", isTextArea: true },
|
||||
{ subLabel: '渠道名', value: '', col: 'name', desc: "想要设置的渠道名字" },
|
||||
],
|
||||
tips: {
|
||||
@@ -75,6 +75,4 @@ CONSTANT.WAYS_DATA.forEach(element => {
|
||||
CONSTANT.WAYS_DATA_MAP[element.type] = element
|
||||
});
|
||||
|
||||
console.log('xxxxxxxx', CONSTANT.WAYS_DATA_MAP)
|
||||
|
||||
export { CONSTANT }
|
||||
@@ -22,7 +22,8 @@
|
||||
<el-table-column label="创建时间" prop="created_on" width="160px" />
|
||||
<el-table-column label="状态" prop="status" width="120px">
|
||||
<template #default="scope">
|
||||
<el-button link size="small" style="margin-right: 10px;" type="primary" @click="drawer = true; logText = scope.row.log">日志</el-button>
|
||||
<el-button link size="small" style="margin-right: 10px;" type="primary"
|
||||
@click="drawer = true; logText = scope.row.log">日志</el-button>
|
||||
<el-tag v-if="scope.row.status == 0" type="danger">失败</el-tag>
|
||||
<el-tag v-if="scope.row.status == 1" type="success">成功</el-tag>
|
||||
</template>
|
||||
@@ -47,7 +48,7 @@
|
||||
import { reactive, toRefs, onMounted } from 'vue'
|
||||
import { request } from '../../../api/api'
|
||||
import { copyToClipboard } from '../../../util/clipboard.js';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { CONSTANT } from '@/constant'
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user