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;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Primitives;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using System; using System;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.API namespace IRaCIS.Core.API
{ {
@ -28,74 +30,101 @@ namespace IRaCIS.Core.API
}) })
.AddJwtBearer(options => .AddJwtBearer(options =>
{ {
options.TokenValidationParameters = new TokenValidationParameters options.TokenValidationParameters = new TokenValidationParameters
{ {
ValidIssuer = jwtSetting.Issuer, ValidIssuer = jwtSetting.Issuer,
ValidAudience = jwtSetting.Audience, ValidAudience = jwtSetting.Audience,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSetting.SecurityKey)), IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSetting.SecurityKey)),
// 默认 300s // 默认 300s
ClockSkew = TimeSpan.Zero ClockSkew = TimeSpan.Zero
}; };
// OPTION 1: use `Invio.Extensions.Authentication.JwtBearer`
options.AddQueryStringAuthentication();
//).AddJwtBearerQueryStringAuthentication( options.Events = new JwtBearerEvents
// (JwtBearerQueryStringOptions options) => {
// { OnMessageReceived = (context) =>
// options.QueryStringParameterName = "access_token"; {
// options.QueryStringBehavior = QueryStringBehaviors.Redact;
// };
// OPTION 2: do it manually if (!context.Request.Query.TryGetValue("access_token", out StringValues values))
{
return Task.CompletedTask;
}
#region var queryToken = values.FirstOrDefault();
//options.Events = new JwtBearerEvents
//{
// OnMessageReceived = (context) => {
// if (!context.Request.Query.TryGetValue("access_token", out StringValues values)) if (!String.IsNullOrWhiteSpace(queryToken))
// { {
// return Task.CompletedTask; context.Token = queryToken;
// }
// if (values.Count > 1) return Task.CompletedTask;
// { }
// 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 cookieToken = context.Request.Cookies["access_token"];
// }
// var token = values.Single(); if (!String.IsNullOrWhiteSpace(cookieToken))
{
context.Token = cookieToken;
// if (String.IsNullOrWhiteSpace(token)) return Task.CompletedTask;
// { }
// 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;
// } }
};
// context.Token = token; // OPTION 1: use `Invio.Extensions.Authentication.JwtBearer`
// return Task.CompletedTask; //options.AddQueryStringAuthentication();
// }
//};
#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 => { }); .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)) .Where(t => t.IsDeleted == false && !t.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id) && t.NeedConfirmedUserTypeList.Any(u => u.NeedConfirmUserTypeId == _userInfo.UserTypeId))
.CountAsync(); .CountAsync();
result.OtherData = new { NeedSignCount= needSignTrialDocCount + needSignSystemDocCount , NeedSignTrialDocCount= needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount } ; result.OtherData = new { NeedSignCount = needSignTrialDocCount + needSignSystemDocCount, NeedSignTrialDocCount = needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount };
return result; return result;
} }
@ -333,7 +333,19 @@ namespace IRaCIS.Core.Application.Services
.WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name)) .WhereIf(!string.IsNullOrEmpty(querySystemDocument.Name), t => t.Name.Contains(querySystemDocument.Name))
.WhereIf(querySystemDocument.FileTypeId != null, t => t.FileTypeId == querySystemDocument.FileTypeId); .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 };
} }