Sort Ordering Usings and Add Support for User ID in OpenActions ...

This commit is contained in:
2026-10-30 00:15:51 +03:30
parent bc49b0aa86
commit 3b099a3089
10 changed files with 64 additions and 85 deletions
+2 -28
View File
@@ -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<Claim> {
//
// 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 ...
@@ -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<string>();
var allowedScopes = keyModel.AllowedScopes.IsNullOrEmpty()
? []
@@ -499,7 +499,7 @@ namespace xIds.Providers
}
//
var requiredScopes =
var requiredScopes =
requiredScope.IsNullOrEmpty()
? []
: requiredScope.ParseListString<string>();
@@ -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();
}
@@ -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,