last ...
This commit is contained in:
@@ -63,6 +63,27 @@ namespace xIds.Controllers
|
|||||||
XException.NotFound.Throw();
|
XException.NotFound.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Noramlize TimeSpan ...
|
||||||
|
var expirationTimeSpan = TimeSpan
|
||||||
|
.FromMinutes(apiKeyConfiguration.DefaultExpirationMinutes);
|
||||||
|
if (
|
||||||
|
request.ExpirationMinutes.HasValue &&
|
||||||
|
request.ExpirationMinutes.Value > 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Normalize Expiration Minutes ...
|
||||||
|
int minutes = request.ExpirationMinutes.Value;
|
||||||
|
if (minutes > apiKeyConfiguration.MaxExpirationMinutes)
|
||||||
|
{
|
||||||
|
minutes = apiKeyConfiguration.MaxExpirationMinutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
expirationTimeSpan = TimeSpan.FromMinutes(minutes);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await provider.CreateApiKey(
|
var result = await provider.CreateApiKey(
|
||||||
userInfo: userInfo,
|
userInfo: userInfo,
|
||||||
@@ -70,7 +91,7 @@ namespace xIds.Controllers
|
|||||||
applicationId: applicationId,
|
applicationId: applicationId,
|
||||||
rateLimit: request.RateLimit,
|
rateLimit: request.RateLimit,
|
||||||
allowedIPs: request.AllowedIPs,
|
allowedIPs: request.AllowedIPs,
|
||||||
expiration: request.Expiration,
|
expiration: expirationTimeSpan,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using IdentityServer4.Extensions;
|
|||||||
using xIdentityModels.Extensions;
|
using xIdentityModels.Extensions;
|
||||||
using Microsoft.EntityFrameworkCore.Query;
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using AutoMapper;
|
||||||
|
|
||||||
namespace xIds.Providers
|
namespace xIds.Providers
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,7 @@ namespace xIds.Providers
|
|||||||
private readonly IXIdentityManager identityManager;
|
private readonly IXIdentityManager identityManager;
|
||||||
private readonly XDataServiceConfiguration configuration;
|
private readonly XDataServiceConfiguration configuration;
|
||||||
private readonly XApiKeyConfiguration apiKeyConfiguration;
|
private readonly XApiKeyConfiguration apiKeyConfiguration;
|
||||||
|
private readonly Action<IMapperConfigurationExpression> mapperConfigurationExp;
|
||||||
|
|
||||||
public XApplicationProvider(
|
public XApplicationProvider(
|
||||||
IMemoryCache cache,
|
IMemoryCache cache,
|
||||||
@@ -45,6 +47,23 @@ namespace xIds.Providers
|
|||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.identityManager = identityManager;
|
this.identityManager = identityManager;
|
||||||
this.apiKeyConfiguration = apiKeyConfiguration;
|
this.apiKeyConfiguration = apiKeyConfiguration;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Configure Mapper Options ...
|
||||||
|
mapperConfigurationExp = cfg =>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
cfg.CreateMap<XApiKey, XApiKeyDto>()
|
||||||
|
.ReverseMap();
|
||||||
|
|
||||||
|
//
|
||||||
|
cfg.CreateMap<XApplication, XApplicationDto>()
|
||||||
|
.ReverseMap();
|
||||||
|
|
||||||
|
//
|
||||||
|
cfg.CreateMap<XApiKeyUsage, XApiKeyUsageDto>()
|
||||||
|
.ReverseMap();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -305,7 +324,8 @@ namespace xIds.Providers
|
|||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
if (currentCount >= limitPerMinute) {
|
if (currentCount >= limitPerMinute)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace xIds.Providers
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result = source.MapConvert<XApiKeyDto, XApiKey>();
|
var result = source.MapConvert<XApiKeyDto, XApiKey>(mapperConfigurationExp);
|
||||||
result = await EnrichAsync(
|
result = await EnrichAsync(
|
||||||
source: result,
|
source: result,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
@@ -88,7 +88,7 @@ namespace xIds.Providers
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result = source.MapConvert<XApiKeyUsageDto, XApiKeyUsage>();
|
var result = source.MapConvert<XApiKeyUsageDto, XApiKeyUsage>(mapperConfigurationExp);
|
||||||
result = await EnrichAsync(
|
result = await EnrichAsync(
|
||||||
source: result,
|
source: result,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
@@ -110,7 +110,7 @@ namespace xIds.Providers
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result = source.MapConvert<XApplicationDto, XApplication>();
|
var result = source.MapConvert<XApplicationDto, XApplication>(mapperConfigurationExp);
|
||||||
result = await EnrichAsync(
|
result = await EnrichAsync(
|
||||||
source: result,
|
source: result,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
|
|||||||
@@ -37,12 +37,12 @@
|
|||||||
"MaxFileSize": 41943040
|
"MaxFileSize": 41943040
|
||||||
},
|
},
|
||||||
"ApiKeyConfiguration": {
|
"ApiKeyConfiguration": {
|
||||||
"ApiPrefix": "xapp",
|
"ApiKeyPrefix": "xapp",
|
||||||
"DefaultRateLimit": 60,
|
"DefaultRateLimit": 60,
|
||||||
"EnableAuditLog": false,
|
"EnableAuditLog": false,
|
||||||
"MaxKeysPerApplication": "10",
|
"MaxKeysPerApplication": 10,
|
||||||
"MaxExpirationMinutes": "525600",
|
"MaxExpirationMinutes": 525600,
|
||||||
"DefaultExpirationMinutes": "43200"
|
"DefaultExpirationMinutes": 43200
|
||||||
},
|
},
|
||||||
"DbSeeder": {
|
"DbSeeder": {
|
||||||
"UpdateExists": false,
|
"UpdateExists": false,
|
||||||
|
|||||||
Reference in New Issue
Block a user