fix 人脸url重新获取
This commit is contained in:
@@ -52,13 +52,13 @@ public class AssignmentsController : ControllerBase
|
||||
await _assignmentService.UpdateDeviceTaskStatusAsync(request);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取新token
|
||||
/// 获取新人脸照片
|
||||
/// </summary>
|
||||
/// <param name="taskId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("token")]
|
||||
public async Task<string> Token(long taskId)
|
||||
[HttpGet("renewfaceurl")]
|
||||
public async Task<string> RenewFaceUrlAsync(long taskId)
|
||||
{
|
||||
return await _assignmentService.Token(taskId);
|
||||
return await _assignmentService.RenewFaceUrlAsync(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ public interface IAssignmentService : IScopeDependency
|
||||
Task UpdateDeviceTaskStatusAsync(UpdateDeviceTaskStatusRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 获取新token
|
||||
/// 获取新人脸照片
|
||||
/// </summary>
|
||||
/// <param name="taskId"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> Token(long taskId);
|
||||
Task<string> RenewFaceUrlAsync(long taskId);
|
||||
}
|
||||
|
||||
@@ -153,37 +153,36 @@ public class AssignmentService : IAssignmentService
|
||||
}).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取新token
|
||||
/// </summary>
|
||||
/// <param name="taskId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<string> Token(long taskId)
|
||||
public async Task<string> RenewFaceUrlAsync(long taskId)
|
||||
{
|
||||
var task = await _dbContext.Queryable<DeviceTaskEntity>().Where(x => x.Id == taskId).FirstAsync();
|
||||
var task = await _dbContext.Queryable<DeviceTaskEntity>().Where(x => x.Id == taskId).FirstAsync();
|
||||
task.ThrowIfNull("该任务不存在");
|
||||
|
||||
var isSuccess = task.Status != DeviceTaskStatusEnumType.Success ? true : false;
|
||||
isSuccess.ThrowIfTrue("设备任务下发状态需为完成");
|
||||
(task.Status != DeviceTaskStatusEnumType.Process).ThrowIfTrue($"设备任务下发状态需为{DeviceTaskStatusEnumType.Process.GetDescription()}");
|
||||
|
||||
string newtoken="";
|
||||
Scoped.Request.Value.Create((sp) =>
|
||||
return Scoped.Request.Value.Create((sp) =>
|
||||
{
|
||||
FaceUrlOptions faceUrlOptions = sp.GetService<IOptions<FaceUrlOptions>>().Value;
|
||||
var dataProtectionProvider = sp.GetService<IDataProtectionProvider>();
|
||||
|
||||
var timeLimitedDataProtector = dataProtectionProvider
|
||||
.CreateProtector("down:face")
|
||||
.ToTimeLimitedDataProtector();
|
||||
.CreateProtector("down:face")
|
||||
.ToTimeLimitedDataProtector();
|
||||
|
||||
var userCode = task.UserCode;
|
||||
|
||||
var key = $"face:{userCode}";
|
||||
var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit));
|
||||
newtoken = faceUrlOptions.Url + token;
|
||||
});
|
||||
|
||||
return newtoken;
|
||||
return faceUrlOptions.Url + token;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -59,12 +59,12 @@ public class MenusController : ControllerBase
|
||||
/// <summary>
|
||||
/// 当前类型的权限分配
|
||||
/// </summary>
|
||||
/// <param name="uniqueType">权限分配类型 MenuAssignmentTypeEnumType</param>
|
||||
/// <param name="uniqueType">权限分配类型 AssignTypeEnumType</param>
|
||||
/// <param name="uniqueValue">类型对应的唯一值</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("assignments")]
|
||||
public async Task<List<string>> GetAssignmentsAsync(
|
||||
[EnumDataType(typeof(MenuAssignmentTypeEnumType))] MenuAssignmentTypeEnumType uniqueType,
|
||||
[EnumDataType(typeof(AssignTypeEnumType))] AssignTypeEnumType uniqueType,
|
||||
[Required] string uniqueValue)
|
||||
{
|
||||
return await _menuService.GetAssignmentCodesAsync(uniqueType, uniqueValue);
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace Dlhis.Sys.Menu.Request;
|
||||
public class MenuPermissionAssignmentRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 权限类型 MenuAssignmentTypeEnumType
|
||||
/// 权限类型 AssignTypeEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(MenuAssignmentTypeEnumType))]
|
||||
public MenuAssignmentTypeEnumType UniqueType { get; set; }
|
||||
[EnumDataType(typeof(AssignTypeEnumType))]
|
||||
public AssignTypeEnumType UniqueType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 唯一值
|
||||
|
||||
@@ -13,7 +13,7 @@ public interface IMenuService : IScopeDependency
|
||||
|
||||
Task AssignmentAsync(MenuPermissionAssignmentRequest request);
|
||||
|
||||
Task<List<string>> GetAssignmentCodesAsync(MenuAssignmentTypeEnumType permissionType, string uniqueData);
|
||||
Task<List<string>> GetAssignmentCodesAsync(AssignTypeEnumType permissionType, string uniqueData);
|
||||
|
||||
Task<List<string>> GetAllAssignmentPermissionsAsync();
|
||||
|
||||
|
||||
@@ -65,13 +65,14 @@ public class MenuService : IMenuService
|
||||
|
||||
public async Task AssignmentAsync(MenuPermissionAssignmentRequest request)
|
||||
{
|
||||
(request.UniqueType == MenuAssignmentTypeEnumType.Role).ThrowIfTrue("暂不支持角色分配");
|
||||
(request.UniqueType == AssignTypeEnumType.Role).ThrowIfTrue("暂不支持角色分配");
|
||||
|
||||
//清空覆盖
|
||||
var permissionsToDelete = await _dbContext.Queryable<MenuPermissionEntity>()
|
||||
.Where(x => x.UniqueType == request.UniqueType)
|
||||
.Where(x => x.UniqueValue == request.UniqueValue)
|
||||
.ToListAsync();
|
||||
|
||||
//触发日志记录
|
||||
await _dbContext.DeleteAsync(permissionsToDelete);
|
||||
|
||||
@@ -80,13 +81,14 @@ public class MenuService : IMenuService
|
||||
Code = x,
|
||||
UniqueType = request.UniqueType,
|
||||
UniqueValue = request.UniqueValue
|
||||
|
||||
}).ToList();
|
||||
|
||||
|
||||
await _dbContext.InsertAsync(permissions);
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetAssignmentCodesAsync(MenuAssignmentTypeEnumType uniqueType, string uniqueData)
|
||||
public async Task<List<string>> GetAssignmentCodesAsync(AssignTypeEnumType uniqueType, string uniqueData)
|
||||
{
|
||||
var permissionCodes = await _dbContext.Queryable<MenuPermissionEntity>()
|
||||
.Where(x => x.UniqueType == uniqueType)
|
||||
@@ -275,7 +277,7 @@ public class MenuService : IMenuService
|
||||
// var groupCodes = await GetAssignmentCodesAsync(MenuPermissionTypeEnumType.Group, manager.usergrp);
|
||||
|
||||
//user
|
||||
var userCodes = await GetAssignmentCodesAsync(MenuAssignmentTypeEnumType.User, user.Id.ToString());
|
||||
var userCodes = await GetAssignmentCodesAsync(AssignTypeEnumType.User, user.Id.ToString());
|
||||
var all = userCodes;// gP.Concat(uP).Distinct().ToList();
|
||||
|
||||
return all;
|
||||
|
||||
@@ -5,34 +5,34 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Dlhis.User.Identity.Controllers
|
||||
namespace Dlhis.User.Identity.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// OAuth2认证
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class OAuth2Controller : ControllerBase
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class OAuth2Controller : ControllerBase
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IOptions<IdentityServerOptions> _identityServerOption;
|
||||
|
||||
public OAuth2Controller(IHttpClientFactory httpClientFactory, IOptions<IdentityServerOptions> identityServerOption)
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IOptions<IdentityServerOptions> _identityServerOption;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_identityServerOption = identityServerOption;
|
||||
}
|
||||
|
||||
public OAuth2Controller(IHttpClientFactory httpClientFactory, IOptions<IdentityServerOptions> identityServerOption, IServiceProvider serviceProvider)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_identityServerOption = identityServerOption;
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
[HttpPost("clientgrant")]
|
||||
public async Task<object> ClientGrant(ClientGrantRequest request)
|
||||
{
|
||||
var authority = _identityServerOption.Value.Authority;
|
||||
|
||||
[HttpPost("clientgrant")]
|
||||
public async Task<object> ClientGrant(ClientGrantRequest request)
|
||||
{
|
||||
var authority = _identityServerOption.Value.Authority;
|
||||
var httpClient = _httpClientFactory.CreateClient("oauth2");
|
||||
|
||||
var httpClient = _httpClientFactory.CreateClient("oauth2");
|
||||
|
||||
var content = new StringContent($"grant_type=client_credentials&client_id={request.ClientId}&client_secret={request.ClientSecret}&scope={request.Scope}", Encoding.UTF8, "application/x-www-form-urlencoded");
|
||||
var response = await httpClient.PostAsync($"{authority}/connect/token", content);
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
return JObject.Parse(result);
|
||||
}
|
||||
var content = new StringContent($"grant_type=client_credentials&client_id={request.ClientId}&client_secret={request.ClientSecret}&scope={request.Scope}", Encoding.UTF8, "application/x-www-form-urlencoded");
|
||||
var response = await httpClient.PostAsync($"{authority}/connect/token", content);
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
return JObject.Parse(result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user