Uat_Study
hang 2022-05-27 14:03:48 +08:00
parent 0c1feb3c5a
commit 938924ebe1
2 changed files with 99 additions and 58 deletions

View File

@ -1,12 +1,14 @@
using Invio.Extensions.Authentication.JwtBearer;
using IRaCIS.Core.Application.Auth;
using IRaCIS.Core.Application.Auth;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Primitives;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.API
{
@ -28,74 +30,101 @@ namespace IRaCIS.Core.API
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = jwtSetting.Issuer,
ValidAudience = jwtSetting.Audience,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSetting.SecurityKey)),
// 默认 300s
ClockSkew = TimeSpan.Zero
};
// OPTION 1: use `Invio.Extensions.Authentication.JwtBearer`
options.AddQueryStringAuthentication();
options.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = jwtSetting.Issuer,
ValidAudience = jwtSetting.Audience,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSetting.SecurityKey)),
// 默认 300s
ClockSkew = TimeSpan.Zero
};
//).AddJwtBearerQueryStringAuthentication(
// (JwtBearerQueryStringOptions options) =>
// {
// options.QueryStringParameterName = "access_token";
// options.QueryStringBehavior = QueryStringBehaviors.Redact;
// };
options.Events = new JwtBearerEvents
{
OnMessageReceived = (context) =>
{
if (!context.Request.Query.TryGetValue("access_token", out StringValues values))
{
return Task.CompletedTask;
}
// OPTION 2: do it manually
var queryToken = values.FirstOrDefault();
#region
//options.Events = new JwtBearerEvents
//{
// OnMessageReceived = (context) => {
if (!String.IsNullOrWhiteSpace(queryToken))
{
context.Token = queryToken;
// if (!context.Request.Query.TryGetValue("access_token", out StringValues values))
// {
// return Task.CompletedTask;
// }
return Task.CompletedTask;
}
// if (values.Count > 1)
// {
// context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
// context.Fail(
// "Only one 'access_token' query string parameter can be defined. " +
// $"However, {values.Count:N0} were included in the request."
// );
var cookieToken = context.Request.Cookies["access_token"];
// return Task.CompletedTask;
// }
if (!String.IsNullOrWhiteSpace(cookieToken))
{
context.Token = cookieToken;
// var token = values.Single();
return Task.CompletedTask;
}
// if (String.IsNullOrWhiteSpace(token))
// {
// context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
// context.Fail(
// "The 'access_token' query string parameter was defined, " +
// "but a value to represent the token was not included."
// );
return Task.CompletedTask;
}
};
// return Task.CompletedTask;
// }
// OPTION 1: use `Invio.Extensions.Authentication.JwtBearer`
// context.Token = token;
//options.AddQueryStringAuthentication();
// return Task.CompletedTask;
// }
//};
#endregion
})
// OPTION 2: do it manually
#region
//options.Events = new JwtBearerEvents
//{
// OnMessageReceived = (context) => {
// if (!context.Request.Query.TryGetValue("access_token", out StringValues values))
// {
// return Task.CompletedTask;
// }
// if (values.Count > 1)
// {
// context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
// context.Fail(
// "Only one 'access_token' query string parameter can be defined. " +
// $"However, {values.Count:N0} were included in the request."
// );
// return Task.CompletedTask;
// }
// var token = values.Single();
// if (String.IsNullOrWhiteSpace(token))
// {
// context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
// context.Fail(
// "The 'access_token' query string parameter was defined, " +
// "but a value to represent the token was not included."
// );
// return Task.CompletedTask;
// }
// context.Token = token;
// return Task.CompletedTask;
// }
//};
#endregion
})
.AddScheme<AuthenticationSchemeOptions, ApiResponseHandler>(nameof(ApiResponseHandler), o => { });
}
}
}
}

View File

@ -209,7 +209,7 @@ namespace IRaCIS.Core.Application.Services
.Where(t => t.IsDeleted == false && !t.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id) && t.NeedConfirmedUserTypeList.Any(u => u.NeedConfirmUserTypeId == _userInfo.UserTypeId))
.CountAsync();
result.OtherData = new { NeedSignCount= needSignTrialDocCount + needSignSystemDocCount , NeedSignTrialDocCount= needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount } ;
result.OtherData = new { NeedSignCount = needSignTrialDocCount + needSignSystemDocCount, NeedSignTrialDocCount = needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount };
return result;
}
@ -333,7 +333,19 @@ namespace IRaCIS.Core.Application.Services
.WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name))
.WhereIf(querySystemDocument.FileTypeId != null, t => t.FileTypeId == querySystemDocument.FileTypeId);
return await unionQuery.ToPagedListAsync(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc);
var reuslt = await unionQuery.ToPagedListAsync(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc);
var needSignTrialDocCount = await _trialDocumentRepository.AsQueryable(true)
.Where(t => t.Trial.TrialUserList.Any(t => t.UserId == _userInfo.Id))
.Where(t => t.IsDeleted == false && !t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id) && t.NeedConfirmedUserTypeList.Any(u => u.NeedConfirmUserTypeId == _userInfo.UserTypeId))
.CountAsync();
var needSignSystemDocCount = await _systemDocumentRepository
.Where(t => t.IsDeleted == false && !t.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id) && t.NeedConfirmedUserTypeList.Any(u => u.NeedConfirmUserTypeId == _userInfo.UserTypeId))
.CountAsync();
result.OtherData = new { NeedSignCount = needSignTrialDocCount + needSignSystemDocCount, NeedSignTrialDocCount = needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount };
}