基于资源授权的最佳实践

This commit is contained in:
administrator committed 2024-04-03 20:39:03 +08:00
1 parent 65925ce6ef
commit 9fdac9de5f
11 files changed
+72 -110

No files matched your search

@@ -13,7 +13,7 @@ public class RemotePermissionChecker(IHttpContextAccessor httpContextAccessor, I
{
private readonly RemotePermissionCheckerOptions _remotePermissionCheckerOptions = options.Value;
public override async Task<bool> IsGrantedAsync(int roleId, string name, string? resourceType = null, string? resourceId = null)
public override async Task<bool> IsGrantedAsync(int roleId, string permissionName, string? resourceType = null, string? resourceId = null)
{
string? accessToken = await HttpContext.GetTokenAsync("access_token");
@@ -25,24 +25,17 @@ public class RemotePermissionChecker(IHttpContextAccessor httpContextAccessor, I
Dictionary<string, string?> parameters = new()
{
{ nameof(roleId), roleId.ToString() },
{ nameof(name), name },
{ nameof(permissionName), permissionName },
{ nameof(resourceType) , resourceType },
{ nameof(resourceId), resourceId }
};
string queryString = QueryHelpers.AddQueryString(string.Empty, parameters);
var permissionGrants = httpClient.GetFromJsonAsAsyncEnumerable<PermissionGrantedResponse>(queryString);
HttpRequestMessage request = new(HttpMethod.Head, queryString);
await foreach (var permissionGrant in permissionGrants)
{
if (permissionGrant != null && permissionGrant.IsGranted)
{
return true;
}
}
HttpResponseMessage response = await httpClient.SendAsync(request);
return false;
return response.IsSuccessStatusCode;
}
}