last ...
This commit is contained in:
@@ -23,7 +23,7 @@ namespace xIds.Configurations
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable audit logging
|
/// Enable audit logging
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool EnableAuditLog { get; set; } = true;
|
public bool EnableAuditLog { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default rate limit (requests per minute)
|
/// Default rate limit (requests per minute)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace xIds.Constants
|
|||||||
{
|
{
|
||||||
public const string DB_SEED_NODE_NAME = "DbSeeder";
|
public const string DB_SEED_NODE_NAME = "DbSeeder";
|
||||||
public const string PROVIDER_NODE_NAME = "DbProvider";
|
public const string PROVIDER_NODE_NAME = "DbProvider";
|
||||||
|
public const string APIKEY_NODE_NAME = "ApiKeyConfiguration";
|
||||||
public const string IDENTITY_NODE_NAME = "IdentityConfiguration";
|
public const string IDENTITY_NODE_NAME = "IdentityConfiguration";
|
||||||
public const string DATA_SERVICE_NODE_NAME = "DataServiceConfiguration";
|
public const string DATA_SERVICE_NODE_NAME = "DataServiceConfiguration";
|
||||||
public const string IDENTITY_RESOURCE_NODE_NAME = "IdentityResourceConfiguration";
|
public const string IDENTITY_RESOURCE_NODE_NAME = "IdentityResourceConfiguration";
|
||||||
|
|||||||
+42
-22
@@ -1,31 +1,31 @@
|
|||||||
using System.Collections.Generic;
|
using xIds.Helpers;
|
||||||
using IdentityServer4;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xCommons.Authorization;
|
|
||||||
using xCommons.Constants;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xExceptions.Constants;
|
|
||||||
using xIdentityHelper;
|
|
||||||
using xIdentityModels;
|
|
||||||
using xIdentityModels.Configurations;
|
|
||||||
using xIds.Configurations;
|
|
||||||
using xIds.Constants;
|
using xIds.Constants;
|
||||||
using xIds.DbContext;
|
using xIds.DbContext;
|
||||||
using xIds.Extensions;
|
|
||||||
using xIds.Helpers;
|
|
||||||
using xIds.Interfaces;
|
|
||||||
using xIds.Providers;
|
using xIds.Providers;
|
||||||
|
using IdentityServer4;
|
||||||
|
using xIdentityHelper;
|
||||||
|
using xIdentityModels;
|
||||||
|
using xIds.Extensions;
|
||||||
|
using xIds.Interfaces;
|
||||||
using xIds.Validators;
|
using xIds.Validators;
|
||||||
|
using xCommons.Constants;
|
||||||
using xMessageService.DI;
|
using xMessageService.DI;
|
||||||
using xMessageService.Interfaces;
|
|
||||||
using xStorageService.DI;
|
using xStorageService.DI;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xIds.Configurations;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using xCommons.Authorization;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using xMessageService.Interfaces;
|
||||||
using xStorageService.Interfaces;
|
using xStorageService.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using xIdentityModels.Configurations;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace xIds.DI
|
namespace xIds.DI
|
||||||
{
|
{
|
||||||
@@ -80,7 +80,7 @@ namespace xIds.DI
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrive XDataService Configurations
|
/// Retrive XDataService Configurations ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
/// <param name="connectionName"></param>
|
/// <param name="connectionName"></param>
|
||||||
@@ -107,6 +107,26 @@ namespace xIds.DI
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve XApiKeyConfiguration Configurations ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static XApiKeyConfiguration GetXApiKeyConfiguration(this IConfiguration source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var section = source
|
||||||
|
.GetSection(Constants.ConfigurationNodeNames.APIKEY_NODE_NAME);
|
||||||
|
var result = section.Get<XApiKeyConfiguration>();
|
||||||
|
if (result.IsNull())
|
||||||
|
{
|
||||||
|
result = new XApiKeyConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register XDataService Configuration
|
/// Register XDataService Configuration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace xIds.DbContext
|
|||||||
public DbSet<XDevice> Devices { get; set; }
|
public DbSet<XDevice> Devices { get; set; }
|
||||||
public DbSet<XApiKey> ApiKeys { get; set; }
|
public DbSet<XApiKey> ApiKeys { get; set; }
|
||||||
public DbSet<XProfileImage> Avatars { get; set; }
|
public DbSet<XProfileImage> Avatars { get; set; }
|
||||||
public DbSet<XApiKeyUsage> ApiKeyUsage { get; set; }
|
public DbSet<XApiKeyUsage> ApiKeyUsages { get; set; }
|
||||||
public DbSet<XApplication> Applications { get; set; }
|
public DbSet<XApplication> Applications { get; set; }
|
||||||
public DbSet<XBannedDevice> BannedDevices { get; set; }
|
public DbSet<XBannedDevice> BannedDevices { get; set; }
|
||||||
public DbSet<XFriendshipFollower> Followers { get; set; }
|
public DbSet<XFriendshipFollower> Followers { get; set; }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using xIds.Interfaces;
|
|
||||||
using xIds.Providers;
|
using xIds.Providers;
|
||||||
|
using xIds.Interfaces;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace xIds.Extensions
|
namespace xIds.Extensions
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
namespace xIds.Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Api Key Generating Helper Class ...
|
||||||
|
/// </summary>
|
||||||
|
public static class XApiKeyHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Generate an Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static (string plainKey, string hash, string prefix) Generate()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Generate 32 bytes of cryptographically secure random data
|
||||||
|
var randomBytes = new byte[32];
|
||||||
|
using (var rng = RandomNumberGenerator.Create())
|
||||||
|
{
|
||||||
|
rng.GetBytes(randomBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Format: xapp_{base64url}
|
||||||
|
var plainKey = $"xapp_{Convert.ToBase64String(randomBytes)
|
||||||
|
.Replace("+", "-").Replace("/", "_").TrimEnd('=')}";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hash with SHA256 for storage (never store plain key)
|
||||||
|
using (var sha256 = SHA256.Create())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(plainKey));
|
||||||
|
var hash = BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prefix for quick identification (first 12 chars)
|
||||||
|
var prefix = plainKey.Substring(0, 16) + "...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return (plainKey, hash, prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verify Generating Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plainKey"></param>
|
||||||
|
/// <param name="storedHash"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool Verify(
|
||||||
|
string plainKey,
|
||||||
|
string storedHash
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
using (var sha256 = SHA256.Create())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(plainKey));
|
||||||
|
var computedHash = BitConverter.ToString(hashBytes)
|
||||||
|
.Replace("-", "").ToLower();
|
||||||
|
|
||||||
|
//
|
||||||
|
return computedHash == storedHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
|
||||||
using Microsoft.IdentityModel.Tokens;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xExceptions.Constants;
|
|
||||||
using xIdentityModels.Configurations;
|
|
||||||
using xIdentityModels.Extensions;
|
|
||||||
using xIdentityModels.Models;
|
|
||||||
using xIds.Interfaces;
|
using xIds.Interfaces;
|
||||||
|
using xCommons.Providers;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using xIdentityModels.Configurations;
|
||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
|
||||||
namespace xIds.Helpers
|
namespace xIds.Helpers
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace xIds.Interfaces
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApplicationDto> AddApplicationAsync(
|
Task<XApplicationDto> AddApplicationAsync(
|
||||||
XApplicationDto item,
|
XApplicationDto item,
|
||||||
XUserClaimsInfoDto userInfo,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -117,12 +117,14 @@ namespace xIds.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="predicate"></param>
|
/// <param name="predicate"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="includeBuilder"></param>
|
/// <param name="includeBuilder"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApplicationDto> FindOneApplicationAsync(
|
Task<XApplicationDto> FindOneApplicationAsync(
|
||||||
Expression<Func<XApplication, bool>> predicate,
|
Expression<Func<XApplication, bool>> predicate,
|
||||||
bool ignoreSoftDeleteds = true,
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -132,6 +134,7 @@ namespace xIds.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="predicate"></param>
|
/// <param name="predicate"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="orderBuilder"></param>
|
/// <param name="orderBuilder"></param>
|
||||||
/// <param name="includeBuilder"></param>
|
/// <param name="includeBuilder"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
@@ -139,6 +142,7 @@ namespace xIds.Interfaces
|
|||||||
Task<IEnumerable<XApplicationDto>> FindManyApplicationAsync(
|
Task<IEnumerable<XApplicationDto>> FindManyApplicationAsync(
|
||||||
Expression<Func<XApplication, bool>> predicate,
|
Expression<Func<XApplication, bool>> predicate,
|
||||||
bool ignoreSoftDeleteds = true,
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
Func<IQueryable<XApplication>, IOrderedQueryable<XApplication>> orderBuilder = null,
|
Func<IQueryable<XApplication>, IOrderedQueryable<XApplication>> orderBuilder = null,
|
||||||
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -149,6 +153,7 @@ namespace xIds.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query"></param>
|
/// <param name="query"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="predicate"></param>
|
/// <param name="predicate"></param>
|
||||||
/// <param name="orderBuilder"></param>
|
/// <param name="orderBuilder"></param>
|
||||||
/// <param name="includeBuilder"></param>
|
/// <param name="includeBuilder"></param>
|
||||||
@@ -157,6 +162,7 @@ namespace xIds.Interfaces
|
|||||||
Task<XQueryResult<XApplicationDto>> QueryApplicationAsync(
|
Task<XQueryResult<XApplicationDto>> QueryApplicationAsync(
|
||||||
XQuery query,
|
XQuery query,
|
||||||
bool ignoreSoftDeleteds = true,
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
Expression<Func<XApplication, bool>> predicate = null,
|
Expression<Func<XApplication, bool>> predicate = null,
|
||||||
Func<IQueryable<XApplication>, IOrderedQueryable<XApplication>> orderBuilder = null,
|
Func<IQueryable<XApplication>, IOrderedQueryable<XApplication>> orderBuilder = null,
|
||||||
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
||||||
@@ -175,7 +181,7 @@ namespace xIds.Interfaces
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApiKeyDto> AddApiKeyAsync(
|
Task<XApiKeyDto> AddApiKeyAsync(
|
||||||
XApiKey item,
|
XApiKey item,
|
||||||
XUserClaimsInfoDto userInfo,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -265,12 +271,14 @@ namespace xIds.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="predicate"></param>
|
/// <param name="predicate"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="includeBuilder"></param>
|
/// <param name="includeBuilder"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApiKeyDto> FindOneApiKeyAsync(
|
Task<XApiKeyDto> FindOneApiKeyAsync(
|
||||||
Expression<Func<XApiKey, bool>> predicate,
|
Expression<Func<XApiKey, bool>> predicate,
|
||||||
bool ignoreSoftDeleteds = true,
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -280,6 +288,7 @@ namespace xIds.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="predicate"></param>
|
/// <param name="predicate"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="orderBuilder"></param>
|
/// <param name="orderBuilder"></param>
|
||||||
/// <param name="includeBuilder"></param>
|
/// <param name="includeBuilder"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
@@ -287,6 +296,7 @@ namespace xIds.Interfaces
|
|||||||
Task<IEnumerable<XApiKeyDto>> FindManyApiKeyAsync(
|
Task<IEnumerable<XApiKeyDto>> FindManyApiKeyAsync(
|
||||||
Expression<Func<XApiKey, bool>> predicate,
|
Expression<Func<XApiKey, bool>> predicate,
|
||||||
bool ignoreSoftDeleteds = true,
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
Func<IQueryable<XApiKey>, IOrderedQueryable<XApiKey>> orderBuilder = null,
|
Func<IQueryable<XApiKey>, IOrderedQueryable<XApiKey>> orderBuilder = null,
|
||||||
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -297,6 +307,7 @@ namespace xIds.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query"></param>
|
/// <param name="query"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="predicate"></param>
|
/// <param name="predicate"></param>
|
||||||
/// <param name="orderBuilder"></param>
|
/// <param name="orderBuilder"></param>
|
||||||
/// <param name="includeBuilder"></param>
|
/// <param name="includeBuilder"></param>
|
||||||
@@ -305,6 +316,7 @@ namespace xIds.Interfaces
|
|||||||
Task<XQueryResult<XApiKeyDto>> QueryApiKeyAsync(
|
Task<XQueryResult<XApiKeyDto>> QueryApiKeyAsync(
|
||||||
XQuery query,
|
XQuery query,
|
||||||
bool ignoreSoftDeleteds = true,
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
Expression<Func<XApiKey, bool>> predicate = null,
|
Expression<Func<XApiKey, bool>> predicate = null,
|
||||||
Func<IQueryable<XApiKey>, IOrderedQueryable<XApiKey>> orderBuilder = null,
|
Func<IQueryable<XApiKey>, IOrderedQueryable<XApiKey>> orderBuilder = null,
|
||||||
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
||||||
@@ -323,7 +335,7 @@ namespace xIds.Interfaces
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApiKeyUsageDto> AddApiKeyUsageAsync(
|
Task<XApiKeyUsageDto> AddApiKeyUsageAsync(
|
||||||
XApiKeyUsageDto item,
|
XApiKeyUsageDto item,
|
||||||
XUserClaimsInfoDto userInfo,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -413,12 +425,14 @@ namespace xIds.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="predicate"></param>
|
/// <param name="predicate"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="includeBuilder"></param>
|
/// <param name="includeBuilder"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApiKeyUsageDto> FindOneApiKeyUsageAsync(
|
Task<XApiKeyUsageDto> FindOneApiKeyUsageAsync(
|
||||||
Expression<Func<XApiKeyUsage, bool>> predicate,
|
Expression<Func<XApiKeyUsage, bool>> predicate,
|
||||||
bool ignoreSoftDeleteds = true,
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -428,6 +442,7 @@ namespace xIds.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="predicate"></param>
|
/// <param name="predicate"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="orderBuilder"></param>
|
/// <param name="orderBuilder"></param>
|
||||||
/// <param name="includeBuilder"></param>
|
/// <param name="includeBuilder"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
@@ -435,6 +450,7 @@ namespace xIds.Interfaces
|
|||||||
Task<IEnumerable<XApiKeyUsageDto>> FindManyApiKeyUsageAsync(
|
Task<IEnumerable<XApiKeyUsageDto>> FindManyApiKeyUsageAsync(
|
||||||
Expression<Func<XApiKeyUsage, bool>> predicate,
|
Expression<Func<XApiKeyUsage, bool>> predicate,
|
||||||
bool ignoreSoftDeleteds = true,
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
Func<IQueryable<XApiKeyUsage>, IOrderedQueryable<XApiKeyUsage>> orderBuilder = null,
|
Func<IQueryable<XApiKeyUsage>, IOrderedQueryable<XApiKeyUsage>> orderBuilder = null,
|
||||||
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -445,6 +461,7 @@ namespace xIds.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query"></param>
|
/// <param name="query"></param>
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="predicate"></param>
|
/// <param name="predicate"></param>
|
||||||
/// <param name="orderBuilder"></param>
|
/// <param name="orderBuilder"></param>
|
||||||
/// <param name="includeBuilder"></param>
|
/// <param name="includeBuilder"></param>
|
||||||
@@ -453,6 +470,7 @@ namespace xIds.Interfaces
|
|||||||
Task<XQueryResult<XApiKeyUsageDto>> QueryApiKeyUsageAsync(
|
Task<XQueryResult<XApiKeyUsageDto>> QueryApiKeyUsageAsync(
|
||||||
XQuery query,
|
XQuery query,
|
||||||
bool ignoreSoftDeleteds = true,
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
Expression<Func<XApiKeyUsage, bool>> predicate = null,
|
Expression<Func<XApiKeyUsage, bool>> predicate = null,
|
||||||
Func<IQueryable<XApiKeyUsage>, IOrderedQueryable<XApiKeyUsage>> orderBuilder = null,
|
Func<IQueryable<XApiKeyUsage>, IOrderedQueryable<XApiKeyUsage>> orderBuilder = null,
|
||||||
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
||||||
@@ -462,10 +480,217 @@ namespace xIds.Interfaces
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Custom Actions ...
|
#region Custom Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Generate a New ApiKey and Add It to DB ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationId"></param>
|
||||||
|
/// <param name="expiration"></param>
|
||||||
|
/// <param name="scopes"></param>
|
||||||
|
/// <param name="allowedIPs"></param>
|
||||||
|
/// <param name="rateLimit"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyDto> CreateApiKey(
|
||||||
|
int applicationId,
|
||||||
|
TimeSpan? expiration = null,
|
||||||
|
IEnumerable<string> scopes = null,
|
||||||
|
IEnumerable<string> allowedIPs = null,
|
||||||
|
int? rateLimit = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Revoke Specified Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKeyId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> RevokeApiKey(
|
||||||
|
Guid apiKeyId,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Renew Specified Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKeyId"></param>
|
||||||
|
/// <param name="newExpiration"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyDto> RotateApiKey(
|
||||||
|
Guid apiKeyId,
|
||||||
|
TimeSpan? newExpiration = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve All Api Keys for Specified Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XApiKeyDto>> GetApplicationApiKeys(
|
||||||
|
Guid applicationId,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate Specified Api Key in based on ClientIP ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKey"></param>
|
||||||
|
/// <param name="clientIP"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> ValidateApiKey(
|
||||||
|
string apiKey,
|
||||||
|
string clientIP,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Enrichers ...
|
#region Enrichers ...
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyDto> EnrichAsync(
|
||||||
|
XApiKey source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyDto> EnrichAsync(
|
||||||
|
XApiKeyDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Api Key Usage ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyUsageDto> EnrichAsync(
|
||||||
|
XApiKeyUsage source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApplicationDto> EnrichAsync(
|
||||||
|
XApplication source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Api Key Usage ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyUsageDto> EnrichAsync(
|
||||||
|
XApiKeyUsageDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApplicationDto> EnrichAsync(
|
||||||
|
XApplicationDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Api Key(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyDto> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApiKey> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Api Key(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyDto> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApiKeyDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Api Key Usage(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyUsageDto> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApiKeyUsage> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Application(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApplicationDto> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApplication> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Api Key Usage(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApiKeyUsageDto> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApiKeyUsageDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Application(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XApplicationDto> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApplicationDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,280 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using xIds.DbContext;
|
||||||
|
using xIds.Interfaces;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xIds.Configurations;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using IdentityServer4.Extensions;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
|
||||||
|
namespace xIds.Providers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// a Service For Manage Security Applications and also Api Key(s) ...
|
||||||
|
/// </summary>
|
||||||
|
public partial class XApplicationProvider : IXApplicationProvider
|
||||||
|
{
|
||||||
|
private readonly string permittedRole;
|
||||||
|
private readonly XIdentityDbContext dbContext;
|
||||||
|
private readonly IXIdentityManager identityManager;
|
||||||
|
private readonly XDataServiceConfiguration configuration;
|
||||||
|
private readonly XApiKeyConfiguration apiKeyConfiguration;
|
||||||
|
|
||||||
|
public XApplicationProvider(
|
||||||
|
XIdentityDbContext dbContext,
|
||||||
|
IXIdentityManager identityManager,
|
||||||
|
XDataServiceConfiguration configuration,
|
||||||
|
XApiKeyConfiguration apiKeyConfiguration,
|
||||||
|
string permittedRole = "admin"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
this.dbContext = dbContext;
|
||||||
|
this.permittedRole = permittedRole;
|
||||||
|
this.configuration = configuration;
|
||||||
|
this.identityManager = identityManager;
|
||||||
|
this.apiKeyConfiguration = apiKeyConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Owner ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XPersonDto> GetOwner(string ownerId)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (ownerId.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var user = await identityManager.GetUserAsync(ownerId);
|
||||||
|
XPersonDto result = user.ToXPerson();
|
||||||
|
if (result.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check Specifed User Info is Owned for Action or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IsOwned(
|
||||||
|
XApplication source,
|
||||||
|
XUserClaimsInfoDto userInfo = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!source.IsNullOrDefault() &&
|
||||||
|
!userInfo.IsNullOrDefault() &&
|
||||||
|
(userInfo.UserId == source.OwnerId ||
|
||||||
|
userInfo.Roles
|
||||||
|
.Any(r =>
|
||||||
|
r.ToNormalString() == permittedRole.ToNormalString()));
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check Specifed User Info is Owned for Action or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IsOwned(
|
||||||
|
XApplicationDto source,
|
||||||
|
XUserClaimsInfoDto userInfo = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!source.IsNullOrDefault() &&
|
||||||
|
!userInfo.IsNullOrDefault() &&
|
||||||
|
(userInfo.UserId == source.OwnerId ||
|
||||||
|
userInfo.Roles
|
||||||
|
.Any(r =>
|
||||||
|
r.ToNormalString() == permittedRole.ToNormalString()));
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Normalize an XQuery based on Data Service Configurations ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="configuration"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public XQuery NormalizeQuery(
|
||||||
|
XQuery source,
|
||||||
|
XDataServiceConfiguration configuration //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (source.IsNull())
|
||||||
|
{
|
||||||
|
source = new XQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Page Size Normalization ...
|
||||||
|
if (source.PageSize < configuration.PagingConfiguration.MinAvailablePageSize)
|
||||||
|
{
|
||||||
|
source.PageSize = configuration.PagingConfiguration.MinAvailablePageSize;
|
||||||
|
}
|
||||||
|
if (source.PageSize > configuration.PagingConfiguration.MaxAvailablePageSize)
|
||||||
|
{
|
||||||
|
source.PageSize = configuration.PagingConfiguration.MaxAvailablePageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prepare a Queryable of Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IQueryable<XApplication> GetApplicationsQeryable(
|
||||||
|
Expression<Func<XApplication, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XApplication>, IOrderedQueryable<XApplication>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Global Result ...
|
||||||
|
var result = dbContext.Applications.AsQueryable();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Filtering ...
|
||||||
|
if (!predicate.IsNull())
|
||||||
|
{
|
||||||
|
result = result.Where(predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Including ...
|
||||||
|
if (!includeBuilder.IsNull())
|
||||||
|
{
|
||||||
|
result = includeBuilder(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Ordering ...
|
||||||
|
if (!orderBuilder.IsNull())
|
||||||
|
{
|
||||||
|
result = orderBuilder(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return result ...
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prepare a Queryable of Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IQueryable<XApiKey> GetApiKeysQeryable(
|
||||||
|
Expression<Func<XApiKey, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XApiKey>, IOrderedQueryable<XApiKey>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Global Result ...
|
||||||
|
var result = dbContext.ApiKeys.AsQueryable();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Filtering ...
|
||||||
|
if (!predicate.IsNull())
|
||||||
|
{
|
||||||
|
result = result.Where(predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Including ...
|
||||||
|
if (!includeBuilder.IsNull())
|
||||||
|
{
|
||||||
|
result = includeBuilder(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Ordering ...
|
||||||
|
if (!orderBuilder.IsNull())
|
||||||
|
{
|
||||||
|
result = orderBuilder(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return result ...
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prepare a Queryable of Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IQueryable<XApiKeyUsage> GetApiKeyUsagesQeryable(
|
||||||
|
Expression<Func<XApiKeyUsage, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IOrderedQueryable<XApiKeyUsage>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Global Result ...
|
||||||
|
var result = dbContext.ApiKeyUsage.AsQueryable();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Filtering ...
|
||||||
|
if (!predicate.IsNull())
|
||||||
|
{
|
||||||
|
result = result.Where(predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Including ...
|
||||||
|
if (!includeBuilder.IsNull())
|
||||||
|
{
|
||||||
|
result = includeBuilder(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Ordering ...
|
||||||
|
if (!orderBuilder.IsNull())
|
||||||
|
{
|
||||||
|
result = orderBuilder(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return result ...
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,773 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using System.Threading;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using xDataService.Extensions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
|
||||||
|
namespace xIds.Providers
|
||||||
|
{
|
||||||
|
public partial class XApplicationProvider
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region ApiKey ...
|
||||||
|
/// <summary>
|
||||||
|
/// Add Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyDto> AddApiKeyAsync(
|
||||||
|
XApiKey item,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!item.IsValidForAdd())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Permission ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Application Exists ...
|
||||||
|
var application = await GetApplicationAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
id: item.ApplicationId,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (application.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Owner ...
|
||||||
|
if (!IsOwned(application, userInfo))
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check COunt of API Keys ...
|
||||||
|
var appApiKeysCount = await dbContext.ApiKeys.CountAsync(
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
predicate: x => x.ApplicationId == item.ApplicationId
|
||||||
|
);
|
||||||
|
if (appApiKeysCount >= apiKeyConfiguration.MaxKeysPerApplication)
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
item.CreatedOn = DateTime.UtcNow;
|
||||||
|
|
||||||
|
//
|
||||||
|
var entity = item.MapConvert<XApiKey, XApiKeyDto>();
|
||||||
|
if (entity.Id.IsValidIntId())
|
||||||
|
{
|
||||||
|
entity.Id = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var entry = await dbContext.ApiKeys.AddAsync(
|
||||||
|
entity: entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
changes <= 0 ||
|
||||||
|
entry.IsNull() ||
|
||||||
|
entry.Entity.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entry.Entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyDto> UpdateApiKeyAsync(
|
||||||
|
Guid id,
|
||||||
|
XApiKeyDto item,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
id != item.Id ||
|
||||||
|
!id.IsDefaultGuid() ||
|
||||||
|
!item.IsValidForAdd() ||
|
||||||
|
item.IsNullOrDefault() ||
|
||||||
|
userInfo.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Exists Entity ...
|
||||||
|
var exists = await dbContext.ApiKeys
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id && !x.Deleted);
|
||||||
|
if (exists.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Permission Checking ...
|
||||||
|
var application = await GetApplicationAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
id: item.ApplicationId,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (application.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
if (!IsOwned(application, userInfo))
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Update Data on Exists Entity ...
|
||||||
|
exists = exists.UpdateData(
|
||||||
|
updateWith: item,
|
||||||
|
propertyWhiteList: [
|
||||||
|
nameof(XApiKey.KeyHash),
|
||||||
|
nameof(XApiKey.KeyPrefix),
|
||||||
|
nameof(XApiKey.ExpiresAt),
|
||||||
|
nameof(XApiKey.CreatedOn),
|
||||||
|
nameof(XApiKey.RevokedAt),
|
||||||
|
nameof(XApiKey.RevokedBy),
|
||||||
|
nameof(XApiKey.LastUsedAt),
|
||||||
|
nameof(XApiKey.AllowedIPs),
|
||||||
|
nameof(XApiKey.ApplicationId),
|
||||||
|
nameof(XApiKey.AllowedScopes),
|
||||||
|
nameof(XApiKey.RateLimitPerMinute),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entry = dbContext.ApiKeys.Attach(exists);
|
||||||
|
entry.State = EntityState.Modified;
|
||||||
|
|
||||||
|
//
|
||||||
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
if (
|
||||||
|
changes <= 0 ||
|
||||||
|
entry.IsNull() ||
|
||||||
|
entry.Entity.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entry.Entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyDto> RemoveApiKeyAsync(
|
||||||
|
Guid id,
|
||||||
|
bool softDelete = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
id.IsDefaultGuid() ||
|
||||||
|
userInfo.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Exists Entity ...
|
||||||
|
var exists = await dbContext.ApiKeys
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id && !x.Deleted);
|
||||||
|
if (exists.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Permission Checking ...
|
||||||
|
var application = await GetApplicationAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
id: exists.ApplicationId,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (application.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
if (!IsOwned(application, userInfo))
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
EntityEntry<XApiKey> entry = null;
|
||||||
|
if (softDelete)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
exists.Deleted = true;
|
||||||
|
entry = dbContext.ApiKeys.Update(exists);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entry = dbContext.ApiKeys.Remove(exists);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
if (
|
||||||
|
changes <= 0 ||
|
||||||
|
entry.IsNull() ||
|
||||||
|
entry.Entity.IsNull()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entry.Entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve an Item by Providing it's ID ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyDto> GetApiKeyAsync(
|
||||||
|
Guid id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (id.IsDefaultGuid() ||
|
||||||
|
userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Condition ...
|
||||||
|
Expression<Func<XApiKey, bool>> predicate = x =>
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Queryable ...
|
||||||
|
var queryable = GetApiKeysQeryable(
|
||||||
|
orderBuilder: null,
|
||||||
|
predicate: predicate,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entity = await queryable.FirstOrDefaultAsync(
|
||||||
|
predicate: x => x.Id == id,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (entity.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Permission Checking ...
|
||||||
|
var application = await GetApplicationAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
id: entity.ApplicationId,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (application.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
if (!IsOwned(application, userInfo))
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve all Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApiKeyDto>> GetAllApiKeyAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKey>, IOrderedQueryable<XApiKey>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var applications = await GetAllApplicationAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
orderBuilder: null,
|
||||||
|
includeBuilder: null,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
applications = applications.Where(a => IsOwned(a, userInfo));
|
||||||
|
var appIds = applications
|
||||||
|
.Select(a => a.Id)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
//
|
||||||
|
Expression<Func<XApiKey, bool>> predicate = x =>
|
||||||
|
appIds.Contains(x.ApplicationId) &&
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
var queryable = GetApiKeysQeryable(
|
||||||
|
predicate: predicate,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var items = await queryable.ToListAsync(cancellationToken);
|
||||||
|
var result = await EnrichRangeAsync(
|
||||||
|
sources: items,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve all Items as Async Enumerable ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async IAsyncEnumerable<XApiKeyDto> GetAllApiKeyAsAsyncEnumerable(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKey>, IOrderedQueryable<XApiKey>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
||||||
|
[EnumeratorCancellation]
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var applications = await GetAllApplicationAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
orderBuilder: null,
|
||||||
|
includeBuilder: null,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
applications = applications.Where(a => IsOwned(a, userInfo));
|
||||||
|
var appIds = applications
|
||||||
|
.Select(a => a.Id)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
//
|
||||||
|
Expression<Func<XApiKey, bool>> predicate = x =>
|
||||||
|
appIds.Contains(x.ApplicationId) &&
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
var queryable = GetApiKeysQeryable(
|
||||||
|
predicate: predicate,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var enumerator = queryable.AsAsyncEnumerable();
|
||||||
|
await foreach (var item in enumerator)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Handle Cancellation Token ...
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var dto = await EnrichAsync(
|
||||||
|
source: item,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
yield return dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find an Item By Providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyDto> FindOneApiKeyAsync(
|
||||||
|
Expression<Func<XApiKey, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Expression<Func<XApiKey, bool>> _predicate = x => !ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
var queryable = GetApiKeysQeryable(
|
||||||
|
orderBuilder: null,
|
||||||
|
predicate: _predicate,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entity = (await queryable
|
||||||
|
.ToListAsync(cancellationToken))
|
||||||
|
.FirstOrDefault(x => predicate.Compile()(x));
|
||||||
|
|
||||||
|
//
|
||||||
|
// Permission Checking ...
|
||||||
|
var application = await GetApplicationAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
id: entity.ApplicationId,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (application.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
if (!IsOwned(application, userInfo))
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find a Collection of Items By Providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApiKeyDto>> FindManyApiKeyAsync(
|
||||||
|
Expression<Func<XApiKey, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKey>, IOrderedQueryable<XApiKey>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Expression<Func<XApiKey, bool>> _predicate = x => !ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
var queryable = GetApiKeysQeryable(
|
||||||
|
orderBuilder: null,
|
||||||
|
predicate: _predicate,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entities = (await queryable
|
||||||
|
.ToListAsync(cancellationToken))
|
||||||
|
.Where(x => predicate.Compile()(x))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
//
|
||||||
|
var appIds = entities
|
||||||
|
.Select(k => k.ApplicationId)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
//
|
||||||
|
foreach (var appId in appIds)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Permission Checking ...
|
||||||
|
var application = await GetApplicationAsync(
|
||||||
|
id: appId,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
application.IsNullOrDefault() ||
|
||||||
|
!IsOwned(application, userInfo))
|
||||||
|
{
|
||||||
|
entities = [.. entities.Where(e => e.ApplicationId != appId)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichRangeAsync(
|
||||||
|
sources: entities,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Items based on XQuery Pagination Structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XApiKeyDto>> QueryApiKeyAsync(
|
||||||
|
XQuery query,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Expression<Func<XApiKey, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XApiKey>, IOrderedQueryable<XApiKey>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKey>, IIncludableQueryable<XApiKey, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Normalize Query ...
|
||||||
|
query = NormalizeQuery(query, configuration);
|
||||||
|
|
||||||
|
//
|
||||||
|
Expression<Func<XApiKey, bool>> _predicate = x => !ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
var queryable = GetApiKeysQeryable(
|
||||||
|
predicate: _predicate,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var items = (await queryable
|
||||||
|
.ToListAsync(cancellationToken))
|
||||||
|
.Where(x => predicate.Compile()(x));
|
||||||
|
|
||||||
|
//
|
||||||
|
var appIds = items
|
||||||
|
.Select(k => k.ApplicationId)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
//
|
||||||
|
foreach (var appId in appIds)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Permission Checking ...
|
||||||
|
var application = await GetApplicationAsync(
|
||||||
|
id: appId,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
application.IsNullOrDefault() ||
|
||||||
|
!IsOwned(application, userInfo))
|
||||||
|
{
|
||||||
|
items = [.. items.Where(e => e.ApplicationId != appId)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var totalItemsCount = items.Count();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Filter ...
|
||||||
|
if (!query.Filter.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
items = items
|
||||||
|
.AsEnumerable()
|
||||||
|
.ApplyFilter(query.Filter);
|
||||||
|
}
|
||||||
|
int filteredItemsCount = items.Count();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Count Pages ...
|
||||||
|
var totalPagesCount = query.CountPages(totalItemsCount);
|
||||||
|
var filteredPagesCount = query.CountPages(filteredItemsCount);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Paging and Sorting ...
|
||||||
|
if (totalItemsCount > 0 &&
|
||||||
|
filteredItemsCount > 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Apply Sorting ...
|
||||||
|
items = items
|
||||||
|
.ToList()
|
||||||
|
.ApplySorting(
|
||||||
|
query.SortBy,
|
||||||
|
query.IsAscending
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Paging ...
|
||||||
|
items = items
|
||||||
|
.ToList()
|
||||||
|
.ApplyPaging(
|
||||||
|
query.Page,
|
||||||
|
query.PageSize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var resultItems = await EnrichRangeAsync(
|
||||||
|
sources: items,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Result ...
|
||||||
|
var result = new XQueryResult<XApiKeyDto>
|
||||||
|
{
|
||||||
|
Page = query.Page,
|
||||||
|
Items = [.. resultItems],
|
||||||
|
PageSize = query.PageSize,
|
||||||
|
TotalPages = totalPagesCount,
|
||||||
|
TotalItems = totalItemsCount,
|
||||||
|
TotalFilteredPages = filteredPagesCount,
|
||||||
|
TotalFilteredItems = filteredItemsCount
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,531 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using System.Threading;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using xDataService.Extensions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
|
||||||
|
namespace xIds.Providers
|
||||||
|
{
|
||||||
|
public partial class XApplicationProvider
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region ApiKeyUsage ...
|
||||||
|
/// <summary>
|
||||||
|
/// Add Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyUsageDto> AddApiKeyUsageAsync(
|
||||||
|
XApiKeyUsageDto item,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!item.IsValidForAdd())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check ApiKey Exists ...
|
||||||
|
var apiKey = await dbContext.ApiKeys
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == item.ApiKeyId);
|
||||||
|
if (apiKey.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check apiKey Activation ...
|
||||||
|
if (!apiKey.IsActive())
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var entity = item.MapConvert<XApiKeyUsage, XApiKeyUsageDto>();
|
||||||
|
var entry = await dbContext.ApiKeyUsages.AddAsync(
|
||||||
|
entity: entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
if (
|
||||||
|
changes <= 0 ||
|
||||||
|
entry.IsNull() ||
|
||||||
|
entry.Entity.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entry.Entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyUsageDto> UpdateApiKeyUsageAsync(
|
||||||
|
long id,
|
||||||
|
XApiKeyUsageDto item,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
id <= 0 ||
|
||||||
|
id != item.Id ||
|
||||||
|
!item.IsValidForAdd() ||
|
||||||
|
item.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Item Exists ...
|
||||||
|
var exists = dbContext.ApiKeyUsages.FirstOrDefault(x => x.Id == id);
|
||||||
|
if (exists.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Update Data on Exists Entity ...
|
||||||
|
exists = exists.UpdateData(
|
||||||
|
updateWith: item,
|
||||||
|
propertyWhiteList: [
|
||||||
|
nameof(XApiKeyUsage.ApiKeyId),
|
||||||
|
nameof(XApiKeyUsage.Endpoint),
|
||||||
|
nameof(XApiKeyUsage.ClientIP),
|
||||||
|
nameof(XApiKeyUsage.HttpMethod),
|
||||||
|
nameof(XApiKeyUsage.StatusCode),
|
||||||
|
nameof(XApiKeyUsage.RequestedOn),
|
||||||
|
nameof(XApiKeyUsage.ResponseTimeMs),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entry = dbContext.ApiKeyUsages.Attach(exists);
|
||||||
|
entry.State = EntityState.Modified;
|
||||||
|
|
||||||
|
//
|
||||||
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
if (
|
||||||
|
changes <= 0 ||
|
||||||
|
entry.IsNull() ||
|
||||||
|
entry.Entity.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entry.Entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyUsageDto> RemoveApiKeyUsageAsync(
|
||||||
|
long id,
|
||||||
|
bool softDelete = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (id <= 0)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Exists Entity ...
|
||||||
|
var exists = await dbContext.ApiKeyUsages
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id && !x.Deleted);
|
||||||
|
if (exists.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
EntityEntry<XApiKeyUsage> entry = null;
|
||||||
|
if (softDelete)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
exists.Deleted = true;
|
||||||
|
entry = dbContext.ApiKeyUsages.Update(exists);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entry = dbContext.ApiKeyUsages.Remove(exists);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
if (
|
||||||
|
changes <= 0 ||
|
||||||
|
entry.IsNull() ||
|
||||||
|
entry.Entity.IsNull()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entry.Entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve an Item by Providing it's ID ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyUsageDto> GetApiKeyUsageAsync(
|
||||||
|
long id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (id <= 0)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Condition ...
|
||||||
|
Expression<Func<XApiKeyUsage, bool>> predicate = x =>
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Queryable ...
|
||||||
|
var queryable = GetApiKeyUsagesQeryable(
|
||||||
|
orderBuilder: null,
|
||||||
|
predicate: predicate,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entity = await queryable.FirstOrDefaultAsync(
|
||||||
|
predicate: x => x.Id == id,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (entity.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve all Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApiKeyUsageDto>> GetAllApiKeyUsageAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IOrderedQueryable<XApiKeyUsage>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Expression<Func<XApiKeyUsage, bool>> predicate = x =>
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
var queryable = GetApiKeyUsagesQeryable(
|
||||||
|
predicate: predicate,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var items = await queryable.ToListAsync(cancellationToken);
|
||||||
|
var result = await EnrichRangeAsync(
|
||||||
|
sources: items,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve all Items as Async Enumerable ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async IAsyncEnumerable<XApiKeyUsageDto> GetAllApiKeyUsageAsAsyncEnumerable(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IOrderedQueryable<XApiKeyUsage>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
||||||
|
[EnumeratorCancellation]
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Expression<Func<XApiKeyUsage, bool>> predicate = x =>
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
var queryable = GetApiKeyUsagesQeryable(
|
||||||
|
predicate: predicate,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var enumerator = queryable.AsAsyncEnumerable();
|
||||||
|
await foreach (var item in enumerator)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Handle Cancellation Token ...
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var dto = await EnrichAsync(
|
||||||
|
source: item,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
yield return dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find an Item By Providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyUsageDto> FindOneApiKeyUsageAsync(
|
||||||
|
Expression<Func<XApiKeyUsage, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Expression<Func<XApiKeyUsage, bool>> _predicate = x => !ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
var queryable = GetApiKeyUsagesQeryable(
|
||||||
|
orderBuilder: null,
|
||||||
|
predicate: _predicate,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entity = (await queryable
|
||||||
|
.ToListAsync(cancellationToken))
|
||||||
|
.FirstOrDefault(x => predicate.Compile()(x));
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find a Collection of Items By Providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApiKeyUsageDto>> FindManyApiKeyUsageAsync(
|
||||||
|
Expression<Func<XApiKeyUsage, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IOrderedQueryable<XApiKeyUsage>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Expression<Func<XApiKeyUsage, bool>> _predicate = x => !ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
var queryable = GetApiKeyUsagesQeryable(
|
||||||
|
orderBuilder: null,
|
||||||
|
predicate: _predicate,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entities = (await queryable
|
||||||
|
.ToListAsync(cancellationToken))
|
||||||
|
.Where(x => predicate.Compile()(x))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichRangeAsync(
|
||||||
|
sources: entities,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Items based on XQuery Pagination Structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XApiKeyUsageDto>> QueryApiKeyUsageAsync(
|
||||||
|
XQuery query,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Expression<Func<XApiKeyUsage, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IOrderedQueryable<XApiKeyUsage>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApiKeyUsage>, IIncludableQueryable<XApiKeyUsage, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Normalize Query ...
|
||||||
|
query = NormalizeQuery(query, configuration);
|
||||||
|
|
||||||
|
//
|
||||||
|
var items = await GetAllApiKeyUsageAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
var totalItemsCount = items.Count();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Filter ...
|
||||||
|
if (!query.Filter.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
items = items
|
||||||
|
.ApplyFilter(query.Filter);
|
||||||
|
}
|
||||||
|
int filteredItemsCount = items.Count();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Count Pages ...
|
||||||
|
var totalPagesCount = query.CountPages(totalItemsCount);
|
||||||
|
var filteredPagesCount = query.CountPages(filteredItemsCount);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Paging and Sorting ...
|
||||||
|
if (totalItemsCount > 0 &&
|
||||||
|
filteredItemsCount > 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Apply Sorting ...
|
||||||
|
items = items
|
||||||
|
.ToList()
|
||||||
|
.ApplySorting(
|
||||||
|
query.SortBy,
|
||||||
|
query.IsAscending
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Paging ...
|
||||||
|
items = items
|
||||||
|
.ToList()
|
||||||
|
.ApplyPaging(
|
||||||
|
query.Page,
|
||||||
|
query.PageSize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Result ...
|
||||||
|
var result = new XQueryResult<XApiKeyUsageDto>
|
||||||
|
{
|
||||||
|
Page = query.Page,
|
||||||
|
Items = [.. items],
|
||||||
|
PageSize = query.PageSize,
|
||||||
|
TotalPages = totalPagesCount,
|
||||||
|
TotalItems = totalItemsCount,
|
||||||
|
TotalFilteredPages = filteredPagesCount,
|
||||||
|
TotalFilteredItems = filteredItemsCount
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,624 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using System.Threading;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using xDataService.Extensions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
|
using xIdentityHelper.Extensions;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
|
||||||
|
namespace xIds.Providers
|
||||||
|
{
|
||||||
|
public partial class XApplicationProvider
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Application ...
|
||||||
|
/// <summary>
|
||||||
|
/// Add Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApplicationDto> AddApplicationAsync(
|
||||||
|
XApplicationDto item,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!item.IsValidForAdd())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Permission ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
item.OwnerId = userInfo.UserId;
|
||||||
|
item.CreatedOn = DateTime.UtcNow;
|
||||||
|
|
||||||
|
//
|
||||||
|
var entity = item.MapConvert<XApplication, XApplicationDto>();
|
||||||
|
if (entity.Id.IsValidIntId())
|
||||||
|
{
|
||||||
|
entity.Id = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var entry = await dbContext.Applications.AddAsync(
|
||||||
|
entity: entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
changes <= 0 ||
|
||||||
|
entry.IsNull() ||
|
||||||
|
entry.Entity.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entry.Entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApplicationDto> UpdateApplicationAsync(
|
||||||
|
int id,
|
||||||
|
XApplicationDto item,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
id != item.Id ||
|
||||||
|
!id.IsValidIntId() ||
|
||||||
|
item.IsNullOrDefault() ||
|
||||||
|
userInfo.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Exists Entity ...
|
||||||
|
var exists = await dbContext.Applications
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id && !x.Deleted);
|
||||||
|
if (exists.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Permission Checking ...
|
||||||
|
if (!IsOwned(exists, userInfo))
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Update Data on Exists Entity ...
|
||||||
|
exists = exists.UpdateData(
|
||||||
|
updateWith: item,
|
||||||
|
propertyWhiteList: [
|
||||||
|
nameof(XApplication.Name),
|
||||||
|
nameof(XApplication.Type),
|
||||||
|
nameof(XApplication.OwnerId),
|
||||||
|
nameof(XApplication.IsActive),
|
||||||
|
nameof(XApplication.CreatedOn),
|
||||||
|
nameof(XApplication.UpdatedAt),
|
||||||
|
nameof(XApplication.Description),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entry = dbContext.Applications.Attach(exists);
|
||||||
|
entry.State = EntityState.Modified;
|
||||||
|
|
||||||
|
//
|
||||||
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
if (
|
||||||
|
changes <= 0 ||
|
||||||
|
entry.IsNull() ||
|
||||||
|
entry.Entity.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entry.Entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApplicationDto> RemoveApplicationAsync(
|
||||||
|
int id,
|
||||||
|
bool softDelete = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
!id.IsValidIntId() ||
|
||||||
|
userInfo.IsNullOrDefault()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Exists Entity ...
|
||||||
|
var exists = await dbContext.Applications
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id && !x.Deleted);
|
||||||
|
if (exists.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Permission Checking ...
|
||||||
|
if (!IsOwned(exists, userInfo))
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
EntityEntry<XApplication> entry = null;
|
||||||
|
if (softDelete)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
exists.Deleted = true;
|
||||||
|
entry = dbContext.Applications.Update(exists);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entry = dbContext.Applications.Remove(exists);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
if (
|
||||||
|
changes <= 0 ||
|
||||||
|
entry.IsNull() ||
|
||||||
|
entry.Entity.IsNull()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entry.Entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve an Item by Providing it's ID ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApplicationDto> GetApplicationAsync(
|
||||||
|
int id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!id.IsValidIntId() ||
|
||||||
|
userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Condition ...
|
||||||
|
Expression<Func<XApplication, bool>> predicate = x =>
|
||||||
|
x.OwnerId != userInfo.UserId ||
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
if (userInfo.IsAdmin())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
predicate = x =>
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Queryable ...
|
||||||
|
var queryable = GetApplicationsQeryable(
|
||||||
|
orderBuilder: null,
|
||||||
|
predicate: predicate,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entity = await queryable.FirstOrDefaultAsync(
|
||||||
|
predicate: x => x.Id == id,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve all Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApplicationDto>> GetAllApplicationAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApplication>, IOrderedQueryable<XApplication>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Condition ...
|
||||||
|
Expression<Func<XApplication, bool>> predicate = x =>
|
||||||
|
x.OwnerId == userInfo.UserId &&
|
||||||
|
(!ignoreSoftDeleteds || !x.Deleted);
|
||||||
|
if (userInfo.IsAdmin())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
predicate = x =>
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Queryable ...
|
||||||
|
var queryable = GetApplicationsQeryable(
|
||||||
|
predicate: predicate,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var items = await queryable.ToListAsync(cancellationToken);
|
||||||
|
var result = await EnrichRangeAsync(
|
||||||
|
sources: items,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve all Items as Async Enumerable ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async IAsyncEnumerable<XApplicationDto> GetAllApplicationAsAsyncEnumerable(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApplication>, IOrderedQueryable<XApplication>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
||||||
|
[EnumeratorCancellation]
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Condition ...
|
||||||
|
Expression<Func<XApplication, bool>> predicate = x =>
|
||||||
|
x.OwnerId == userInfo.UserId &&
|
||||||
|
(!ignoreSoftDeleteds || !x.Deleted);
|
||||||
|
if (userInfo.IsAdmin())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
predicate = x =>
|
||||||
|
!ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Queryable ...
|
||||||
|
var queryable = GetApplicationsQeryable(
|
||||||
|
predicate: predicate,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var enumerator = queryable.AsAsyncEnumerable();
|
||||||
|
await foreach (var item in enumerator)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Handle Cancellation Token ...
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var dto = await EnrichAsync(
|
||||||
|
source: item,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
yield return dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find an Item By Providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApplicationDto> FindOneApplicationAsync(
|
||||||
|
Expression<Func<XApplication, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Expression<Func<XApplication, bool>> _predicate = x => !ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
if (!userInfo.IsAdmin())
|
||||||
|
{
|
||||||
|
_predicate = x =>
|
||||||
|
x.OwnerId == userInfo.UserId &&
|
||||||
|
(!ignoreSoftDeleteds || !x.Deleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var queryable = GetApplicationsQeryable(
|
||||||
|
orderBuilder: null,
|
||||||
|
predicate: _predicate,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entity = (await queryable
|
||||||
|
.ToListAsync(cancellationToken))
|
||||||
|
.FirstOrDefault(x => predicate.Compile()(x));
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichAsync(
|
||||||
|
source: entity,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find a Collection of Items By Providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApplicationDto>> FindManyApplicationAsync(
|
||||||
|
Expression<Func<XApplication, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Func<IQueryable<XApplication>, IOrderedQueryable<XApplication>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Expression<Func<XApplication, bool>> _predicate = x => !ignoreSoftDeleteds || !x.Deleted;
|
||||||
|
if (!userInfo.IsAdmin())
|
||||||
|
{
|
||||||
|
_predicate = x =>
|
||||||
|
x.OwnerId == userInfo.UserId &&
|
||||||
|
(!ignoreSoftDeleteds || !x.Deleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var queryable = GetApplicationsQeryable(
|
||||||
|
orderBuilder: null,
|
||||||
|
predicate: _predicate,
|
||||||
|
includeBuilder: includeBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
var entities = (await queryable
|
||||||
|
.ToListAsync(cancellationToken))
|
||||||
|
.Where(x => predicate.Compile()(x));
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await EnrichRangeAsync(
|
||||||
|
sources: entities,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Items based on XQuery Pagination Structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="includeBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XApplicationDto>> QueryApplicationAsync(
|
||||||
|
XQuery query,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
Expression<Func<XApplication, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XApplication>, IOrderedQueryable<XApplication>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XApplication>, IIncludableQueryable<XApplication, object>> includeBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Normalize Query ...
|
||||||
|
query = NormalizeQuery(query, configuration);
|
||||||
|
|
||||||
|
//
|
||||||
|
var items = await GetAllApplicationAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
orderBuilder: orderBuilder,
|
||||||
|
includeBuilder: includeBuilder,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||||
|
);
|
||||||
|
var totalItemsCount = items.Count();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Filter ...
|
||||||
|
if (!query.Filter.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
items = items
|
||||||
|
.ApplyFilter(query.Filter);
|
||||||
|
}
|
||||||
|
int filteredItemsCount = items.Count();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Count Pages ...
|
||||||
|
var totalPagesCount = query.CountPages(totalItemsCount);
|
||||||
|
var filteredPagesCount = query.CountPages(filteredItemsCount);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Paging and Sorting ...
|
||||||
|
if (totalItemsCount > 0 &&
|
||||||
|
filteredItemsCount > 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Apply Sorting ...
|
||||||
|
items = items
|
||||||
|
.ToList()
|
||||||
|
.ApplySorting(
|
||||||
|
query.SortBy,
|
||||||
|
query.IsAscending
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Paging ...
|
||||||
|
items = items
|
||||||
|
.ToList()
|
||||||
|
.ApplyPaging(
|
||||||
|
query.Page,
|
||||||
|
query.PageSize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Result ...
|
||||||
|
var result = new XQueryResult<XApplicationDto>
|
||||||
|
{
|
||||||
|
Page = query.Page,
|
||||||
|
Items = [.. items],
|
||||||
|
PageSize = query.PageSize,
|
||||||
|
TotalPages = totalPagesCount,
|
||||||
|
TotalItems = totalItemsCount,
|
||||||
|
TotalFilteredPages = filteredPagesCount,
|
||||||
|
TotalFilteredItems = filteredItemsCount
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xIds.Providers
|
||||||
|
{
|
||||||
|
public partial class XApplicationProvider
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Custom Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Generate a New ApiKey and Add It to DB ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationId"></param>
|
||||||
|
/// <param name="expiration"></param>
|
||||||
|
/// <param name="scopes"></param>
|
||||||
|
/// <param name="allowedIPs"></param>
|
||||||
|
/// <param name="rateLimit"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyDto> CreateApiKey(
|
||||||
|
int applicationId,
|
||||||
|
TimeSpan? expiration = null,
|
||||||
|
IEnumerable<string> scopes = null,
|
||||||
|
IEnumerable<string> allowedIPs = null,
|
||||||
|
int? rateLimit = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
userInfo.IsNullOrDefault() ||
|
||||||
|
!applicationId.IsValidIntId()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Application Exists ...
|
||||||
|
var application = await GetApplicationAsync(
|
||||||
|
id: applicationId,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (application.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Owner ...
|
||||||
|
if (!IsOwned(application, userInfo))
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Normalizing ...
|
||||||
|
if (!rateLimit.HasValue)
|
||||||
|
{
|
||||||
|
rateLimit = apiKeyConfiguration.DefaultRateLimit;
|
||||||
|
}
|
||||||
|
if (!expiration.HasValue)
|
||||||
|
{
|
||||||
|
expiration = TimeSpan.FromMinutes(apiKeyConfiguration.DefaultExpirationMinutes);
|
||||||
|
}
|
||||||
|
else if (expiration.Value > TimeSpan.FromMinutes(apiKeyConfiguration.MaxExpirationMinutes))
|
||||||
|
{
|
||||||
|
expiration = TimeSpan.FromMinutes(apiKeyConfiguration.MaxExpirationMinutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var
|
||||||
|
|
||||||
|
//
|
||||||
|
var item = new XApiKeyDto
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Revoke Specified Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKeyId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> RevokeApiKey(
|
||||||
|
Guid apiKeyId,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Renew Specified Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKeyId"></param>
|
||||||
|
/// <param name="newExpiration"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyDto> RotateApiKey(
|
||||||
|
Guid apiKeyId,
|
||||||
|
TimeSpan? newExpiration = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve All Api Keys for Specified Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApiKeyDto>> GetApplicationApiKeys(
|
||||||
|
Guid applicationId,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate Specified Api Key in based on ClientIP ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKey"></param>
|
||||||
|
/// <param name="clientIP"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> ValidateApiKey(
|
||||||
|
string apiKey,
|
||||||
|
string clientIP,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
|
||||||
|
namespace xIds.Providers
|
||||||
|
{
|
||||||
|
public partial class XApplicationProvider
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Enrichers ...
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyDto> EnrichAsync(
|
||||||
|
XApiKey source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyDto> EnrichAsync(
|
||||||
|
XApiKeyDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Api Key Usage ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyUsageDto> EnrichAsync(
|
||||||
|
XApiKeyUsage source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApplicationDto> EnrichAsync(
|
||||||
|
XApplication source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Api Key Usage ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApiKeyUsageDto> EnrichAsync(
|
||||||
|
XApiKeyUsageDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XApplicationDto> EnrichAsync(
|
||||||
|
XApplicationDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Api Key(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApiKeyDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApiKey> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Api Key(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApiKeyDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApiKeyDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Api Key Usage(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApiKeyUsageDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApiKeyUsage> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Application(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApplicationDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApplication> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Api Key Usage(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApiKeyUsageDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApiKeyUsageDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Application(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XApplicationDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XApplicationDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,13 @@
|
|||||||
"ThumbQuality": 72,
|
"ThumbQuality": 72,
|
||||||
"MaxFileSize": 41943040
|
"MaxFileSize": 41943040
|
||||||
},
|
},
|
||||||
|
"ApiKeyConfiguration": {
|
||||||
|
"DefaultRateLimit": 60,
|
||||||
|
"EnableAuditLog": false,
|
||||||
|
"MaxKeysPerApplication": "10",
|
||||||
|
"MaxExpirationMinutes": "525600",
|
||||||
|
"DefaultExpirationMinutes": "43200"
|
||||||
|
},
|
||||||
"DbSeeder": {
|
"DbSeeder": {
|
||||||
"UpdateExists": false,
|
"UpdateExists": false,
|
||||||
"Clients": [
|
"Clients": [
|
||||||
|
|||||||
Reference in New Issue
Block a user