mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:13:26 +08:00
【新增】jwt授权认证方式,增加AES加密解密处理,防止前端进行渗透解密伪造Token可能存在。
This commit is contained in:
@@ -16,6 +16,7 @@ using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Configuration;
|
||||
using static SKIT.FlurlHttpClient.Wechat.Api.Models.WeDataQueryBindListResponse.Types;
|
||||
using NETCore.Encrypt;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers.AliPayOAuth
|
||||
{
|
||||
@@ -137,10 +138,16 @@ namespace CoreCms.Net.Web.WebApi.Controllers.AliPayOAuth
|
||||
//用户标识
|
||||
var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);
|
||||
identity.AddClaims(claims);
|
||||
|
||||
//返回处理结果集
|
||||
var auth = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement);
|
||||
//对token进行非对称加密
|
||||
auth.token = EncryptProvider.AESEncrypt(auth.token, AppSettingsConstVars.JwtConfigSecretKey);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
auth = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement),
|
||||
auth,
|
||||
user
|
||||
};
|
||||
jm.otherData = result.UserId;
|
||||
|
||||
@@ -48,6 +48,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NETCore.Encrypt;
|
||||
using Newtonsoft.Json;
|
||||
using Nito.AsyncEx;
|
||||
using NLog;
|
||||
@@ -252,10 +253,16 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
//用户标识
|
||||
var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);
|
||||
identity.AddClaims(claims);
|
||||
|
||||
//返回处理结果集
|
||||
var auth = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement);
|
||||
//对token进行非对称加密
|
||||
auth.token = EncryptProvider.AESEncrypt(auth.token, AppSettingsConstVars.JwtConfigSecretKey);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
auth = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement),
|
||||
auth,
|
||||
user
|
||||
};
|
||||
jm.otherData = response.OpenId;
|
||||
@@ -355,10 +362,16 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
//用户标识
|
||||
var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);
|
||||
identity.AddClaims(claims);
|
||||
|
||||
//返回处理结果集
|
||||
var auth = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement);
|
||||
//对token进行非对称加密
|
||||
auth.token = EncryptProvider.AESEncrypt(auth.token, AppSettingsConstVars.JwtConfigSecretKey);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
{
|
||||
auth = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement),
|
||||
auth,
|
||||
user
|
||||
};
|
||||
jm.otherData = response.OpenId;
|
||||
@@ -468,8 +481,14 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
//用户标识
|
||||
var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);
|
||||
identity.AddClaims(claims);
|
||||
|
||||
//返回处理结果集
|
||||
var auth = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement);
|
||||
//对token进行非对称加密
|
||||
auth.token = EncryptProvider.AESEncrypt(auth.token, AppSettingsConstVars.JwtConfigSecretKey);
|
||||
|
||||
jm.status = true;
|
||||
jm.data = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement);
|
||||
jm.data = auth;
|
||||
|
||||
//录入登录日志
|
||||
var log = new CoreCmsUserLog();
|
||||
@@ -801,9 +820,15 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
//用户标识
|
||||
var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);
|
||||
identity.AddClaims(claims);
|
||||
|
||||
//返回处理结果集
|
||||
var auth = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement);
|
||||
//对token进行非对称加密
|
||||
auth.token = EncryptProvider.AESEncrypt(auth.token, AppSettingsConstVars.JwtConfigSecretKey);
|
||||
|
||||
jm.status = true;
|
||||
jm.msg = "注册成功";
|
||||
jm.data = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement);
|
||||
jm.data = auth;
|
||||
//录入登录日志
|
||||
var log = new CoreCmsUserLog();
|
||||
log.userId = id;
|
||||
|
||||
Reference in New Issue
Block a user