feat: 授权请求头和查询参数支持accessToken接收

This commit is contained in:
TsMask
2024-03-18 11:11:24 +08:00
parent 6e5cce7c89
commit 43600001ee
4 changed files with 20 additions and 3 deletions

View File

@@ -1,12 +1,12 @@
# 项目信息 # 项目信息
framework: framework:
name: "CN EMS" name: "CN EMS"
version: "2.2401.1" version: "2.2403.1"
# 应用服务配置 # 应用服务配置
server: server:
# 服务端口 # 服务端口
port: 3030 port: 33030
# 是否开启代理 # 是否开启代理
proxy: false proxy: false
@@ -65,6 +65,9 @@ upload:
- ".mp4" - ".mp4"
- ".avi" - ".avi"
- ".rmvb" - ".rmvb"
# 软件包
- ".deb"
- ".rpm"
# cors 跨域 # cors 跨域
cors: cors:
@@ -97,6 +100,8 @@ cors:
- "Accept-Language" - "Accept-Language"
- "Accept" - "Accept"
- "Range" - "Range"
# 非标准请求头
- "accessToken",
- "Accesstoken" - "Accesstoken"
- "Operationtype" - "Operationtype"
# 设置 Access-Control-Expose-Headers 的值 # 设置 Access-Control-Expose-Headers 的值

View File

@@ -1,6 +1,6 @@
# 应用服务配置 # 应用服务配置
server: server:
port: 3030 port: 33030
proxy: true proxy: true
# security 安全 # security 安全

View File

@@ -19,3 +19,6 @@ const JWT_KEY = "user_id"
// 令牌-JWT标识用户登录账号字段 // 令牌-JWT标识用户登录账号字段
const JWT_NAME = "user_name" const JWT_NAME = "user_name"
// NMS北向使用-数据响应字段和请求头授权
const ACCESS_TOKEN = "accessToken"

View File

@@ -65,6 +65,15 @@ func IPAddrLocation(c *gin.Context) (string, string) {
// Authorization 解析请求头 // Authorization 解析请求头
func Authorization(c *gin.Context) string { func Authorization(c *gin.Context) string {
// Query请求查询
if authQuery, ok := c.GetQuery(token.ACCESS_TOKEN); ok && authQuery != "" {
return authQuery
}
// Header请求头
if authHeader := c.GetHeader(token.ACCESS_TOKEN); authHeader != "" {
return authHeader
}
// Query请求查询 // Query请求查询
if authQuery, ok := c.GetQuery(token.RESPONSE_FIELD); ok && authQuery != "" { if authQuery, ok := c.GetQuery(token.RESPONSE_FIELD); ok && authQuery != "" {
return authQuery return authQuery