diff --git a/Extensions/DbExtensions.cs b/Extensions/DbExtensions.cs index f90638e..81edd11 100644 --- a/Extensions/DbExtensions.cs +++ b/Extensions/DbExtensions.cs @@ -1,15 +1,15 @@ using System; +using xIds.Models; +using xIds.Constants; using System.Reflection; +using xIds.Configurations; +using xCommons.Extensions; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; +using xIdentityModels.Configurations; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using MySql.EntityFrameworkCore.Infrastructure; -using xCommons.Extensions; -using xIdentityModels.Configurations; -using xIds.Configurations; -using xIds.Constants; -using xIds.Models; +using Microsoft.EntityFrameworkCore.Infrastructure; namespace xIds.Extensions { diff --git a/Extensions/IIdentityServerBuilderExtensions.cs b/Extensions/IIdentityServerBuilderExtensions.cs index 7b2933d..a6f3a71 100644 --- a/Extensions/IIdentityServerBuilderExtensions.cs +++ b/Extensions/IIdentityServerBuilderExtensions.cs @@ -1,11 +1,11 @@ +using xIds.Constants; +using xCommons.Models; using System.Reflection; -using System.Security.Cryptography.X509Certificates; +using xCommons.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using xCommons.Extensions; -using xCommons.Models; -using xIds.Constants; +using System.Security.Cryptography.X509Certificates; namespace xIds.Extensions { diff --git a/Extensions/IQueryableExtensions.cs b/Extensions/IQueryableExtensions.cs deleted file mode 100644 index 1ac9f29..0000000 --- a/Extensions/IQueryableExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using xCommons.Extensions; -using xExceptions.Constants; -using xModels.Base; -using xIds.Constants; - -namespace xIds.Extensions -{ - public static class IQueryableExtensions - { - } -} \ No newline at end of file diff --git a/Extensions/XDbSeederExtensions.cs b/Extensions/XDbSeederExtensions.cs index 1d1d14d..9bf2d07 100644 --- a/Extensions/XDbSeederExtensions.cs +++ b/Extensions/XDbSeederExtensions.cs @@ -1,20 +1,20 @@ using System; -using System.Collections.Generic; using System.Linq; +using xIds.Models; +using xIds.Constants; +using xIds.Interfaces; +using xCommons.Extensions; using System.Threading.Tasks; -using IdentityServer4.EntityFramework.DbContexts; -using IdentityServer4.EntityFramework.Mappers; +using System.Collections.Generic; +using xIdentityModels.Extensions; +using xIdentityModels.Descriptors; +using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using IdentityServer4.EntityFramework.Mappers; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using xCommons.Extensions; -using xIdentityModels.Descriptors; -using xIdentityModels.Extensions; -using xIds.Constants; -using xIds.Interfaces; -using xIds.Models; +using IdentityServer4.EntityFramework.DbContexts; namespace xIds.Extensions { diff --git a/Extensions/XModelExtensions.cs b/Extensions/XModelExtensions.cs index 789c960..ca2c404 100644 --- a/Extensions/XModelExtensions.cs +++ b/Extensions/XModelExtensions.cs @@ -1,11 +1,11 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; using xCommons.Extensions; -using xDataService.Configuration; +using System.Threading.Tasks; using xIdentityModels.Models; +using System.Collections.Generic; +using xDataService.Configuration; +using Microsoft.EntityFrameworkCore; namespace xIds.Extensions { diff --git a/Helpers/XIdentityHelper.cs b/Helpers/XIdentityHelper.cs index e5283b9..246b5c2 100644 --- a/Helpers/XIdentityHelper.cs +++ b/Helpers/XIdentityHelper.cs @@ -87,9 +87,9 @@ namespace xIds.Helpers var result = new TokenValidationParameters { ValidIssuer = issuer, - ValidAudience = audience, + IssuerSigningKey = key, ValidateLifetime = true, - IssuerSigningKey = key + ValidAudience = audience, }; // diff --git a/Providers/XApiKeyAccessAttribute.cs b/Providers/XApiKeyAccessAttribute.cs index 680a4de..1da9693 100644 --- a/Providers/XApiKeyAccessAttribute.cs +++ b/Providers/XApiKeyAccessAttribute.cs @@ -1,8 +1,6 @@ using System; -using IdentityModel; using xIds.Interfaces; using System.Threading; -using xCommons.Constants; using xCommons.Extensions; using xExceptions.Constants; using System.Security.Claims; @@ -11,12 +9,10 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using xIdentityModels.Constants; using xIdentityService.Constants; -using System.Collections.Generic; +using xIdentityModels.Extensions; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.DependencyInjection; -using xIdentityModels.Dtos; -using xIdentityService.Extensions; namespace xIds.Providers { @@ -142,29 +138,7 @@ namespace xIds.Providers // // Creating Claims ... - var claims = new List { - // - // Owner Identifier of API Key ... - new(ClaimTypes.Name, validationResult.OwnerId), - new(JwtClaimTypes.Subject, validationResult.OwnerId), - // - // Application Id ... - new(XCustomClaims.ApplicationId, validationResult.ApplicationId.ToString()), - // - // Authentication Type ... - new(XCustomClaims.AuthType, apiKeyAuthentication), - }; - - // - // Add Scopes ... - if (validationResult.Scopes != null) - { - // - foreach (var scope in validationResult.Scopes) - { - claims.Add(new Claim(JwtClaimTypes.Scope, scope)); - } - } + var claims = validationResult.ToXClaims(); // // Create Principal and Ticket ... diff --git a/Providers/XApplicationProvider/XApplicationProvider+Custom.cs b/Providers/XApplicationProvider/XApplicationProvider+Custom.cs index 15f6f85..0d2a1fa 100644 --- a/Providers/XApplicationProvider/XApplicationProvider+Custom.cs +++ b/Providers/XApplicationProvider/XApplicationProvider+Custom.cs @@ -304,8 +304,8 @@ namespace xIds.Providers newExpiration = TimeSpan .FromMinutes(apiKeyConfiguration.DefaultExpirationMinutes); } - expiredDate = DateTime.UtcNow.Add(newExpiration.Value); - + expiredDate = DateTime.UtcNow.Add(newExpiration.Value); + // if (!expiredDate.HasValue) { @@ -431,8 +431,8 @@ namespace xIds.Providers // // Here we Have to Parse Allowed Ips and Scopes ... - var allowedIps = keyModel.AllowedIPs.IsNullOrEmpty() - ? [] + var allowedIps = keyModel.AllowedIPs.IsNullOrEmpty() + ? [] : keyModel.AllowedIPs.ParseListString(); var allowedScopes = keyModel.AllowedScopes.IsNullOrEmpty() ? [] @@ -499,7 +499,7 @@ namespace xIds.Providers } // - var requiredScopes = + var requiredScopes = requiredScope.IsNullOrEmpty() ? [] : requiredScope.ParseListString(); @@ -507,10 +507,10 @@ namespace xIds.Providers // // Check Scope and IP is Valid or not ... var isIpValid = allowedIps.IsClientIpPassed(clientIP); - var isScopeValid = + var isScopeValid = allowedScopes .IsScopePassed(requiredScopes); - var isScopeIpValid = + var isScopeIpValid = isIpValid && isScopeValid ; @@ -537,6 +537,27 @@ namespace xIds.Providers isApplicationActive; if (isValid) { + // + // Handle Attach Owner ... + try + { + // + var user = await identityManager.GetUserAsync( + containsDetail: true, + userSelectByParam: application.OwnerId + ); + + // + var owner = user.ToXPerson(); + result.Owner = owner; + } + catch (Exception ex) + { + // + result.Errors.Add($"exception occured: {ex.Message}"); + return result; + } + result.Errors.Clear(); } diff --git a/Providers/XIdentityManager/XIdentityManager+Open.cs b/Providers/XIdentityManager/XIdentityManager+Open.cs index f107424..78e1367 100644 --- a/Providers/XIdentityManager/XIdentityManager+Open.cs +++ b/Providers/XIdentityManager/XIdentityManager+Open.cs @@ -246,10 +246,11 @@ namespace xIds.Providers // Generate a Dynamic Object ... var result = new XOpenActionUserInfoDto { + UserId = userProfile.UserId, + Avatar = userProfile.Avatar, Username = userProfile.UserName, - Firstname = userProfile.FirstName, Lastname = userProfile.LastName, - Avatar = userProfile.Avatar + Firstname = userProfile.FirstName, }; // @@ -276,6 +277,7 @@ namespace xIds.Providers ); var result = profiles.Select(x => new XOpenActionUserInfoDto { + UserId = x.UserId, Avatar = x.Avatar, Username = x.UserName, Lastname = x.LastName, diff --git a/Stores/XPersistedGrantStore.cs b/Stores/XPersistedGrantStore.cs index a2af0f6..f719a00 100644 --- a/Stores/XPersistedGrantStore.cs +++ b/Stores/XPersistedGrantStore.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; -using IdentityServer4.EntityFramework.DbContexts; -using IdentityServer4.EntityFramework.Mappers; using IdentityServer4.Models; using IdentityServer4.Stores; +using System.Threading.Tasks; +using System.Collections.Generic; using Microsoft.EntityFrameworkCore; +using IdentityServer4.EntityFramework.Mappers; +using IdentityServer4.EntityFramework.DbContexts; namespace xIds.Stores {