last ...
This commit is contained in:
@@ -468,6 +468,11 @@ namespace xIds.Interfaces
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
Task<bool> UseApiKey(
|
||||
XOpenActionRequestDto dto,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
Task<XOpenActionUserInfoDto> GetUserInfo(
|
||||
XOpenActionRequestDto dto
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ using xExceptions.Constants;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using xIdentityModels.Models;
|
||||
|
||||
namespace xIds.Providers
|
||||
{
|
||||
@@ -166,6 +167,55 @@ namespace xIds.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use Specified Api Key ...
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UseApiKey(
|
||||
XOpenActionRequestDto model,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Load Model from Request ...
|
||||
var apiKeyUsage = model.Payload.FromJSON<XApiKeyUsageDto>();
|
||||
var result = !apiKeyUsage.IsNullOrDefault();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading ApiKey ...
|
||||
var apiKey = await DbContext.ApiKeys
|
||||
.FirstOrDefaultAsync(x => x.Id == apiKeyUsage.ApiKeyId);
|
||||
apiKey.LastUsedAt = DateTime.UtcNow;
|
||||
DbContext.ApiKeys.Update(apiKey);
|
||||
await DbContext.SaveChangesAsync();
|
||||
|
||||
//
|
||||
// Prepare Entity ...
|
||||
var entiy = new XApiKeyUsage
|
||||
{
|
||||
ApiKeyId = apiKeyUsage.ApiKeyId,
|
||||
Endpoint = apiKeyUsage.Endpoint,
|
||||
ClientIP = apiKeyUsage.ClientIP,
|
||||
HttpMethod = apiKeyUsage.HttpMethod,
|
||||
StatusCode = apiKeyUsage.StatusCode,
|
||||
RequestedOn = apiKeyUsage.RequestedOn,
|
||||
ResponseTimeMs = apiKeyUsage.ResponseTimeMs,
|
||||
};
|
||||
await DbContext.ApiKeyUsages.AddAsync(entiy);
|
||||
var changes = await DbContext.SaveChangesAsync();
|
||||
result = changes > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get User Info For Open Actions ...
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user