diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs index c52cad1..67ffdea 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs @@ -5,17 +5,14 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Controllers; using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Data; using System.Linq; -using System.Net.Http; using System.Reflection; using System.Security.Claims; -using System.Text; -using System.Text.Json; using System.Threading.Tasks; using ServicePermissionContract = Authentications.GeneratedServices.ServicePermissionContract; namespace EasyMicroservices.Cores.AspCoreApi.Authorizations @@ -95,12 +92,22 @@ void AddToTreeDictionary(string roleName, ICollection } } + static Endpoint GetEndpoint(HttpContext context) + { +#if (NETSTANDARD) + return context.Features.Get()?.Endpoint; +#else + return context.GetEndpoint(); +#endif + + } + MessageContract IsAnonymousMethodCalling(HttpContext httpContext) { - var endpoints = httpContext.GetEndpoint(); + var endpoints = GetEndpoint(httpContext); if (endpoints == null) return true; - var controllerActionDescriptor = httpContext.GetEndpoint().Metadata.GetMetadata(); + var controllerActionDescriptor = endpoints.Metadata.GetMetadata(); if (controllerActionDescriptor == null) return (FailedReasonType.Nothing, "controllerActionDescriptor is null or empty, did you sent correct route to me?"); if (controllerActionDescriptor.ControllerTypeInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute)).Any() || @@ -116,8 +123,9 @@ async Task> HasPermission(HttpContext httpContext) return isAnonymousMethodCalling; else if (isAnonymousMethodCalling.Result) return true; - string controllerName = httpContext.Request.RouteValues["controller"].ToString(); - string actionName = httpContext.Request.RouteValues["action"].ToString(); + var actionDescriptor = GetEndpoint(httpContext)?.Metadata?.GetMetadata(); + string controllerName = actionDescriptor.ControllerName; + string actionName = actionDescriptor.ActionName; List roleClaims = httpContext.User.FindAll(ClaimTypes.Role).ToList(); if (roleClaims.Count == 0) return (FailedReasonType.AccessDenied, $"There is no claim role founded! did you forgot to use services.AddAuthentication? or did you set Bearer for authorize? controllerName: {controllerName} actionName: {actionName}"); diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index 0909e71..904c2dd 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -1,10 +1,10 @@  - net6.0;net7.0;net8.0 + netstandard2.1;net6.0;net7.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.1 + 0.0.1.2 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet @@ -14,11 +14,7 @@ .\bin\$(Configuration)\$(TargetFramework)\EasyMicroservices.Cores.AspCoreApi.xml README.md - - - - - + @@ -28,6 +24,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj index a3839aa..e4bfc28 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj @@ -4,7 +4,7 @@ net6.0;net7.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.1 + 0.0.1.2 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet,aspcore,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj index 5ce8b08..02cbd99 100644 --- a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.1 + 0.0.1.2 core of database. EasyMicroservices@gmail.com core,cores,base,client,clients diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj index 99881a7..016620d 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net45;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.1 + 0.0.1.2 core contracts. EasyMicroservices@gmail.com core,cores,base,contract,contracts,dto,dtos diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index ca4a297..adb6f46 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net45;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.1 + 0.0.1.2 core of database. EasyMicroservices@gmail.com core,cores,base,database diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index d192098..b56e08a 100644 --- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj @@ -1,10 +1,10 @@  - net6.0;net8.0 + netstandard2.1;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.1 + 0.0.1.2 ef core of database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj index 4f6b265..35a8948 100644 --- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj @@ -1,10 +1,10 @@  - net6.0;net8.0 + netstandard2.1;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.1 + 0.0.1.2 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational @@ -30,7 +30,11 @@ - + + + + +