- Add XApiKeyAccess Authorization Attribute ...
- Refactor XApiAccountEndpoint and Add Application Routes into it ... - Refactor IXIdentityProvider and XIdentityProvider and Add Support for Calling ApplicationController on xIds and Retrieve Responses of it ... - Add XBaseTestIdentity Controller and Add Support for Test ApiKey Based Authorization on it ...
This commit is contained in:
@@ -7,16 +7,14 @@ using xExceptions.Constants;
|
||||
using System.Threading.Tasks;
|
||||
using xIdentityModels.Models;
|
||||
using xHttpService.Constants;
|
||||
using xHttpService.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityService.Constants;
|
||||
using xHttpService.Extensions;
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace xIdentityService.Providers
|
||||
{
|
||||
public partial class XIdentityProvider
|
||||
{
|
||||
|
||||
//
|
||||
#region Applications ...
|
||||
//
|
||||
@@ -65,11 +63,13 @@ namespace xIdentityService.Providers
|
||||
/// Update Specified Application ...
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XApplicationDto> UpdateApplication(
|
||||
XTokenResponse tokens,
|
||||
int id,
|
||||
XApplicationDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -84,12 +84,21 @@ namespace xIdentityService.Providers
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync();
|
||||
if (!id.IsValidIntId())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var client = GetRestClient(tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet(XApiAccountEndpoint.UpdateApplication);
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.UpdateApplication,
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||
}
|
||||
);
|
||||
request.AddJsonBody(item);
|
||||
|
||||
//
|
||||
@@ -181,7 +190,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.GetApplication,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||
}
|
||||
);
|
||||
@@ -227,7 +236,7 @@ namespace xIdentityService.Providers
|
||||
|
||||
//
|
||||
// Attach XQuery to Request ...
|
||||
request = request.AttachXQuery (query);
|
||||
request = request.AttachXQuery(query);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XQueryResult<XApplicationDto>>(
|
||||
@@ -307,7 +316,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.GetApiKey,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||
}
|
||||
);
|
||||
@@ -351,7 +360,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.RemoveApiKey,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||
}
|
||||
);
|
||||
@@ -369,11 +378,13 @@ namespace xIdentityService.Providers
|
||||
/// Update Specified ApiKey ...
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XApiKeyDto> UpdateApiKey(
|
||||
XTokenResponse tokens,
|
||||
Guid id,
|
||||
XApiKeyDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -382,12 +393,17 @@ namespace xIdentityService.Providers
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddIsGuid(id)
|
||||
.AddNotNull(item)
|
||||
.AddNotNull(tokens)
|
||||
.AddNotEmpty(
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync();
|
||||
if (id != item.Id)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var client = GetRestClient(tokens);
|
||||
@@ -395,8 +411,8 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.UpdateApiKey,
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XId.GetStringValue (), item.Id.ToString() }
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||
}
|
||||
);
|
||||
request.AddJsonBody(item);
|
||||
@@ -442,7 +458,7 @@ namespace xIdentityService.Providers
|
||||
|
||||
//
|
||||
// Attach XQuery to Request ...
|
||||
request = request.AttachXQuery (query);
|
||||
request = request.AttachXQuery(query);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XQueryResult<XApiKeyDto>>(
|
||||
@@ -565,7 +581,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.GetApiKeyUsage,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||
}
|
||||
);
|
||||
@@ -612,7 +628,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.RemoveApiKeyUsage,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||
}
|
||||
);
|
||||
@@ -630,11 +646,13 @@ namespace xIdentityService.Providers
|
||||
/// Update Specified Api Key Usage ...
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XApiKeyUsageDto> UpdateApiKeyUsage(
|
||||
XTokenResponse tokens,
|
||||
long id,
|
||||
XApiKeyUsageDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -649,6 +667,9 @@ namespace xIdentityService.Providers
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync();
|
||||
if (id <= 0 || id != item.Id) {
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var client = GetRestClient(tokens);
|
||||
@@ -658,7 +679,7 @@ namespace xIdentityService.Providers
|
||||
XApiAccountEndpoint.UpdateApiKeyUsage,
|
||||
@params: new Dictionary<string, string>
|
||||
{
|
||||
{ XParam.XId.GetStringValue (), item.Id.ToString() }
|
||||
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||
}
|
||||
);
|
||||
request.AddJsonBody(item);
|
||||
@@ -704,7 +725,7 @@ namespace xIdentityService.Providers
|
||||
|
||||
//
|
||||
// Attach XQuery to Request ...
|
||||
request = request.AttachXQuery (query);
|
||||
request = request.AttachXQuery(query);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XQueryResult<XApiKeyUsageDto>>(
|
||||
@@ -790,7 +811,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.ShowApiKey,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XApiKeyId.GetStringValue (), apiKeyId.ToString() },
|
||||
{ XParam.XApplicationId.GetStringValue (), applicationId.ToString() }
|
||||
}
|
||||
@@ -841,9 +862,9 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.CreateApiKey,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XApplicationId.GetStringValue (), applicationId.ToString() }
|
||||
}
|
||||
}
|
||||
);
|
||||
request.AddJsonBody(createRequest);
|
||||
|
||||
@@ -891,8 +912,8 @@ namespace xIdentityService.Providers
|
||||
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.RemoveApiKey,
|
||||
@params: new Dictionary<string, string> {
|
||||
XApiAccountEndpoint.RemoveApiKeyCustom,
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XApiKeyId.GetStringValue (), apiKeyId.ToString() },
|
||||
{ XParam.XApplicationId.GetStringValue (), applicationId.ToString() }
|
||||
}
|
||||
@@ -945,7 +966,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.RotateApiKey,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XApiKeyId.GetStringValue (), apiKeyId.ToString() },
|
||||
{ XParam.XApplicationId.GetStringValue (), applicationId.ToString() }
|
||||
}
|
||||
@@ -997,7 +1018,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.RevokeApiKey,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XApiKeyId.GetStringValue (), apiKeyId.ToString() },
|
||||
{ XParam.XApplicationId.GetStringValue (), applicationId.ToString() }
|
||||
}
|
||||
@@ -1045,7 +1066,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.GetApiKeys,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XApplicationId.GetStringValue (), applicationId.ToString() }
|
||||
}
|
||||
);
|
||||
@@ -1095,7 +1116,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
XApiAccountEndpoint.GetApiKeyUsages,
|
||||
@params: new Dictionary<string, string> {
|
||||
@params: new Dictionary<string, string> {
|
||||
{ XParam.XApiKeyId.GetStringValue (), apiKeyId.ToString() },
|
||||
{ XParam.XApplicationId.GetStringValue (), applicationId.ToString() }
|
||||
}
|
||||
@@ -1132,7 +1153,7 @@ namespace xIdentityService.Providers
|
||||
var client = GetRestClient();
|
||||
|
||||
//
|
||||
var checksum = SecurityProvider.Encrypt(validationRequest.ToJson()).ToMd5String();
|
||||
var checksum = SecurityProvider.Encrypt(validationRequest.ToJSON()).ToMd5String();
|
||||
|
||||
//
|
||||
var request = GetRestRequet(
|
||||
@@ -1141,6 +1162,7 @@ namespace xIdentityService.Providers
|
||||
{ XHeader.ChecksumDigest.GetStringValue(), checksum }
|
||||
}
|
||||
);
|
||||
request.AddJsonBody(validationRequest);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XApiKeyValidationResult>(
|
||||
|
||||
Reference in New Issue
Block a user