Feat: jwt token加密算法由ES256更换为HS256

This commit is contained in:
2022-04-03 13:29:47 +08:00
parent ec4c957b25
commit e1f6d3c822
8 changed files with 34 additions and 188 deletions

View File

@@ -1,4 +1,4 @@
# 应用版本,应与当前版本一致
# 应用版本
version: {{ .Version }}
# 应用配置
@@ -15,9 +15,8 @@ security:
expire: 14400
# Refresh Token过期时间 (默认24小时)
refresh-expire: 86400
# 以下字段指定key的文件路径
private-key: id_ecdsa
public-key: id_ecdsa.pub
# 请确保签名密钥安全性足够高,建议使用高强度随机字符串
secret: {{ .Security.Jwt.Secret }}
# 允许额外的跨域请求
allow-CORS:
- "*"
@@ -31,7 +30,7 @@ database:
# mysql https://github.com/go-sql-driver/mysql#dsn-data-source-name
# postgres https://github.com/lib/pq
# with unit second
max-idle-conns: 20
max-open-conns: 50
# with unit sec
conn-max-life-time: 30

View File

@@ -22,8 +22,7 @@ type Config struct {
Jwt struct {
Expire uint32
RefreshExpire uint32 `yaml:"refresh-expire"`
PrivateKey string `yaml:"private-key"`
PublicKey string `yaml:"public-key"`
Secret string
}
}
Database struct {
@@ -39,6 +38,9 @@ var configFull string
// 加载配置文件
func SetupConfig() {
// 加载默认配置
Cfg = DefCfg
// 读取配置文件,若不存在则创建
if isExist := utils.FileExist("config.yml"); !isExist {
newCfgFile()
@@ -82,6 +84,9 @@ func parseConfigTmpl() []byte {
// 创建配置文件
func newCfgFile() {
// 生成Key
Cfg.Security.Jwt.Secret = utils.NewKey()
// 解析配置文件模板
tmplBytes := parseConfigTmpl()

View File

@@ -3,5 +3,5 @@ package config
import "testing"
func TestSetupConfig(t *testing.T) {
Cfg.Version = "0.0.1-dev"
SetupConfig()
}

5
config/defaults.go Normal file
View File

@@ -0,0 +1,5 @@
package config
var DefCfg = Config{
Version: "0.0.1-dev",
}