|
@@ -1,9 +1,11 @@
|
|
|
-using Microsoft.AspNetCore.Mvc;
|
|
|
+using IES.ExamLib.Models;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
using Microsoft.Extensions.Primitives;
|
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
|
using System.Security;
|
|
|
using ZXing.QrCode.Internal;
|
|
|
+using static System.Formats.Asn1.AsnWriter;
|
|
|
|
|
|
namespace IES.ExamServer.Filters
|
|
|
{
|
|
@@ -27,7 +29,7 @@ namespace IES.ExamServer.Filters
|
|
|
if (authTokenAttribute!=null)
|
|
|
{
|
|
|
|
|
|
- if (string.IsNullOrWhiteSpace(authtoken) || !JwtAuthExtension.ValidateAuthToken(authtoken, "fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA="))
|
|
|
+ if (string.IsNullOrWhiteSpace(authtoken) || !JwtAuthExtension.ValidateAuthToken(authtoken, ExamConstant.JwtSecretKey))
|
|
|
{
|
|
|
context.Result = new Microsoft.AspNetCore.Mvc.UnauthorizedResult();
|
|
|
}
|
|
@@ -38,7 +40,7 @@ namespace IES.ExamServer.Filters
|
|
|
else { needParse=true; }
|
|
|
if (needParse)
|
|
|
{
|
|
|
- if (!string.IsNullOrWhiteSpace(authtoken) && JwtAuthExtension.ValidateAuthToken(authtoken, "fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA="))
|
|
|
+ if (!string.IsNullOrWhiteSpace(authtoken) && JwtAuthExtension.ValidateAuthToken(authtoken, ExamConstant.JwtSecretKey))
|
|
|
{
|
|
|
//string msg = "";
|
|
|
//int code = 0;
|
|
@@ -50,7 +52,7 @@ namespace IES.ExamServer.Filters
|
|
|
}
|
|
|
var jwt = new JwtSecurityTokenHandler().ReadJwtToken(authtoken);
|
|
|
id = jwt.Payload.Sub;
|
|
|
- school = jwt.Payload.Azp;
|
|
|
+ //school = jwt.Payload.Azp;
|
|
|
name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
|
|
|
picture = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("picture"))?.Value;
|
|
|
scope = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("scope"))?.Value;
|
|
@@ -76,7 +78,7 @@ namespace IES.ExamServer.Filters
|
|
|
context.HttpContext.Items.Add("ID", id);
|
|
|
context.HttpContext.Items.Add("Name", name);
|
|
|
context.HttpContext.Items.Add("Picture", picture);
|
|
|
- context.HttpContext.Items.Add("School", school);
|
|
|
+ //context.HttpContext.Items.Add("School", school);
|
|
|
context.HttpContext.Items.Add("Roles", _roles);
|
|
|
context.HttpContext.Items.Add("Scope", scope);
|
|
|
context.HttpContext.Items.Add("TimeZone", TimeZone);
|
|
@@ -88,12 +90,19 @@ namespace IES.ExamServer.Filters
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- var _roles = new List<string> { "Guest" }; // 默认角色,访客角色
|
|
|
+ var _roles = new List<string> { "visitor" }; // 默认角色,访客角色
|
|
|
context.HttpContext.Items.Add("Roles", _roles);
|
|
|
context.HttpContext.Items.Add("TimeZone", TimeZone);
|
|
|
+ context.HttpContext.Items.Add("ID", $"{DateTimeOffset.Now.ToUnixTimeSeconds()}");
|
|
|
+ context.HttpContext.Items.Add("Name", $"访客{Random.Shared.Next(100,999)}");
|
|
|
+ context.HttpContext.Items.Add("Picture", null);
|
|
|
+ context.HttpContext.Items.Add("Scope", "visitor");
|
|
|
}
|
|
|
}
|
|
|
- else { context.Result = new Microsoft.AspNetCore.Mvc.UnauthorizedResult(); }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ context.Result = new Microsoft.AspNetCore.Mvc.UnauthorizedResult();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|