✨Feat: jwt token加密算法由ES256更换为HS256
This commit is contained in:
@@ -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
|
||||
|
@@ -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()
|
||||
|
||||
|
@@ -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
5
config/defaults.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package config
|
||||
|
||||
var DefCfg = Config{
|
||||
Version: "0.0.1-dev",
|
||||
}
|
Reference in New Issue
Block a user