last ...
This commit is contained in:
@@ -468,6 +468,11 @@ namespace xIds.Interfaces
|
|||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Task<bool> UseApiKey(
|
||||||
|
XOpenActionRequestDto dto,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
Task<XOpenActionUserInfoDto> GetUserInfo(
|
Task<XOpenActionUserInfoDto> GetUserInfo(
|
||||||
XOpenActionRequestDto dto
|
XOpenActionRequestDto dto
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using xExceptions.Constants;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
|
||||||
namespace xIds.Providers
|
namespace xIds.Providers
|
||||||
{
|
{
|
||||||
@@ -166,6 +167,55 @@ namespace xIds.Providers
|
|||||||
return result;
|
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>
|
/// <summary>
|
||||||
/// Get User Info For Open Actions ...
|
/// Get User Info For Open Actions ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user