- 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:
@@ -0,0 +1,201 @@
|
|||||||
|
using System;
|
||||||
|
using IdentityModel;
|
||||||
|
using System.Threading;
|
||||||
|
using xCommons.Constants;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using xIdentityModels.Constants;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using xIdentityService.Constants;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace xIdentityService.Attributes
|
||||||
|
{
|
||||||
|
[AttributeUsage(
|
||||||
|
AttributeTargets.Class | AttributeTargets.Method,
|
||||||
|
AllowMultiple = false,
|
||||||
|
Inherited = true
|
||||||
|
)]
|
||||||
|
public class XApiKeyAccessAttribute : AuthorizeAttribute, IAuthorizationFilter
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Optional allowed scopes. If empty, no scope enforcement.
|
||||||
|
/// </summary>
|
||||||
|
public XApiKeyScope[] Scopes { get; set; }
|
||||||
|
|
||||||
|
public XApiKeyAccessAttribute(
|
||||||
|
XApiKeyScope[] scopes = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (!scopes.HasChild())
|
||||||
|
{
|
||||||
|
scopes = [XApiKeyScope.Read];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Scopes = scopes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Authorization Filtering ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
public void OnAuthorization(AuthorizationFilterContext context)
|
||||||
|
{
|
||||||
|
Task.FromResult(OnAuthorizationAsync(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handle Authorization Filtering Using Tasks ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task OnAuthorizationAsync(
|
||||||
|
AuthorizationFilterContext context,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Access HttpContext ...
|
||||||
|
var http = context.HttpContext;
|
||||||
|
var error = XException.NotAuthorized.ToXError();
|
||||||
|
var apiKeyAuthentication = XAuthenticationScheme.XApiKey.GetStringValue();
|
||||||
|
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Obtain the endpoint currently being executed
|
||||||
|
var endpointFeature = http.Features.Get<IEndpointFeature>();
|
||||||
|
var endpoint = endpointFeature?.Endpoint;
|
||||||
|
if (endpoint.IsNull() ||
|
||||||
|
endpointFeature.IsNull()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
error.Message = "Endpoint not Accessible ...";
|
||||||
|
context.Result = new UnauthorizedObjectResult(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Identity Provider Service from DI ...
|
||||||
|
var identityService = http.RequestServices
|
||||||
|
.GetService<IXIdentityProvider>();
|
||||||
|
if (identityService.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
error.Message = "Api Key Service not Registered ...";
|
||||||
|
context.Result = new UnauthorizedObjectResult(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Checking Header ...
|
||||||
|
var apiKeyHeader = XHeader.ApiKey.GetStringValue();
|
||||||
|
if (!http.Request.Headers.ContainsKey(apiKeyHeader))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
error.Message = "ApiKey not Exists ...";
|
||||||
|
context.Result = new UnauthorizedObjectResult(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Extract ApiKey from Header ...
|
||||||
|
var apiKey = http.Request.Headers[apiKeyHeader].ToString();
|
||||||
|
if (apiKey.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
error.Message = "ApiKey not Provided ...";
|
||||||
|
context.Result = new UnauthorizedObjectResult(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Extract Client IP ...
|
||||||
|
var clientIP = http.Request.HttpContext.Connection.RemoteIpAddress?.ToString();
|
||||||
|
var scopes =
|
||||||
|
!Scopes.HasChild()
|
||||||
|
? string.Empty
|
||||||
|
: Scopes.ToListString();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Validation Request ...
|
||||||
|
var validationRequest = new XApiKeyValidationRequest
|
||||||
|
{
|
||||||
|
ApiKey = apiKey,
|
||||||
|
ClientIP = clientIP,
|
||||||
|
RequiredScope = scopes
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validating ApiKey ...
|
||||||
|
var validationResponse = identityService.ValidateApiKey(
|
||||||
|
request: validationRequest,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
)
|
||||||
|
.GetAwaiter()
|
||||||
|
.GetResult();
|
||||||
|
if (validationResponse.Errors.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var message = validationResponse.Errors.ToListString(',');
|
||||||
|
error.Message = message;
|
||||||
|
context.Result = new UnauthorizedObjectResult(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Creating Claims ...
|
||||||
|
var claims = new List<Claim> {
|
||||||
|
//
|
||||||
|
// Owner Identifier of API Key ...
|
||||||
|
new(ClaimTypes.Name, validationResponse.OwnerId),
|
||||||
|
new(JwtClaimTypes.Subject, validationResponse.OwnerId),
|
||||||
|
//
|
||||||
|
// Application Id ...
|
||||||
|
new(XCustomClaims.ApplicationId, validationResponse.ApplicationId.ToString()),
|
||||||
|
//
|
||||||
|
// Authentication Type ...
|
||||||
|
new(XCustomClaims.AuthType, apiKeyAuthentication),
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add Scopes ...
|
||||||
|
if (validationResponse.Scopes != null)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
foreach (var scope in validationResponse.Scopes)
|
||||||
|
{
|
||||||
|
claims.Add(new Claim(JwtClaimTypes.Scope, scope));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create Principal and Ticket ...
|
||||||
|
var identity = new ClaimsIdentity(claims, apiKeyAuthentication);
|
||||||
|
var principal = new ClaimsPrincipal(identity);
|
||||||
|
|
||||||
|
//
|
||||||
|
http.User = principal;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//
|
||||||
|
error.Message = "ApiKey authorization failed ...";
|
||||||
|
context.Result = new UnauthorizedObjectResult(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -221,7 +221,7 @@ namespace xIdentityService.Constants
|
|||||||
[StringValue("Applications")]
|
[StringValue("Applications")]
|
||||||
CreateApplication,
|
CreateApplication,
|
||||||
|
|
||||||
[StringValue("Applications")]
|
[StringValue("Applications/{id}")]
|
||||||
UpdateApplication,
|
UpdateApplication,
|
||||||
|
|
||||||
[StringValue("Applications/{id}")]
|
[StringValue("Applications/{id}")]
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
using xCommons.Providers;
|
||||||
|
using xCommons.Attributes;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using xIdentityModels.Constants;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using xIdentityService.Attributes;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
|
namespace xIdentityService.Controllers
|
||||||
|
{
|
||||||
|
public abstract class XBaseTestIdentityController : XBaseIdentityController
|
||||||
|
{
|
||||||
|
protected XBaseTestIdentityController(
|
||||||
|
ILogger<XBaseTestIdentityController> logger,
|
||||||
|
XAppConfiguration appConfiguration,
|
||||||
|
IXIdentityProvider identityProvider,
|
||||||
|
XValidationProvider validationProvider
|
||||||
|
) : base(logger, appConfiguration, identityProvider, validationProvider)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
#region ApiKey Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello for Accessing ApiKey Authorization ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[XApiKeyAccess]
|
||||||
|
[AllowAnonymous]
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiApiKeyAccess")]
|
||||||
|
public ActionResult<string> HiApiKeyAccess()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi ApiKey Access, is Passed ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello for Accessing ApiKey Read Access ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiApiKeyReadAccess")]
|
||||||
|
[XApiKeyAccess(Scopes = [XApiKeyScope.Read])]
|
||||||
|
public ActionResult<string> HiApiKeyReadAccess()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi ApiKey Read Access, is Passed ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello for Accessing ApiKey Write Access ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiApiKeyWriteAccess")]
|
||||||
|
[XApiKeyAccess(scopes: [XApiKeyScope.Write])]
|
||||||
|
public ActionResult<string> HiApiKeyWriteAccess()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi ApiKey Write Access, is Passed ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello for Accessing ApiKey Manage Access ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiApiKeyManageAccess")]
|
||||||
|
[XApiKeyAccess(scopes: [XApiKeyScope.Manage])]
|
||||||
|
public ActionResult<string> HiApiKManageAccess()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi ApiKey Manage Access, is Passed ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello for Accessing ApiKey Admin Access ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiApiKeyAdminAccess")]
|
||||||
|
[XApiKeyAccess(scopes: [XApiKeyScope.Admin])]
|
||||||
|
public ActionResult<string> HiApiKeyAdminAccess()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi ApiKey Admin Access, is Passed ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -369,11 +369,13 @@ namespace xIdentityService.Interfaces
|
|||||||
/// Update Specified Application ...
|
/// Update Specified Application ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tokens"></param>
|
/// <param name="tokens"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApplicationDto> UpdateApplication(
|
Task<XApplicationDto> UpdateApplication(
|
||||||
XTokenResponse tokens,
|
XTokenResponse tokens,
|
||||||
|
int id,
|
||||||
XApplicationDto item,
|
XApplicationDto item,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -461,11 +463,13 @@ namespace xIdentityService.Interfaces
|
|||||||
/// Update Specified ApiKey ...
|
/// Update Specified ApiKey ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tokens"></param>
|
/// <param name="tokens"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApiKeyDto> UpdateApiKey(
|
Task<XApiKeyDto> UpdateApiKey(
|
||||||
XTokenResponse tokens,
|
XTokenResponse tokens,
|
||||||
|
Guid id,
|
||||||
XApiKeyDto item,
|
XApiKeyDto item,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -540,11 +544,13 @@ namespace xIdentityService.Interfaces
|
|||||||
/// Update Specified Api Key Usage ...
|
/// Update Specified Api Key Usage ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tokens"></param>
|
/// <param name="tokens"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApiKeyUsageDto> UpdateApiKeyUsage(
|
Task<XApiKeyUsageDto> UpdateApiKeyUsage(
|
||||||
XTokenResponse tokens,
|
XTokenResponse tokens,
|
||||||
|
long id,
|
||||||
XApiKeyUsageDto item,
|
XApiKeyUsageDto item,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,16 +7,14 @@ using xExceptions.Constants;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xIdentityModels.Models;
|
using xIdentityModels.Models;
|
||||||
using xHttpService.Constants;
|
using xHttpService.Constants;
|
||||||
|
using xHttpService.Extensions;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using xIdentityService.Constants;
|
using xIdentityService.Constants;
|
||||||
using xHttpService.Extensions;
|
|
||||||
using MongoDB.Bson;
|
|
||||||
|
|
||||||
namespace xIdentityService.Providers
|
namespace xIdentityService.Providers
|
||||||
{
|
{
|
||||||
public partial class XIdentityProvider
|
public partial class XIdentityProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Applications ...
|
#region Applications ...
|
||||||
//
|
//
|
||||||
@@ -65,11 +63,13 @@ namespace xIdentityService.Providers
|
|||||||
/// Update Specified Application ...
|
/// Update Specified Application ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tokens"></param>
|
/// <param name="tokens"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XApplicationDto> UpdateApplication(
|
public async Task<XApplicationDto> UpdateApplication(
|
||||||
XTokenResponse tokens,
|
XTokenResponse tokens,
|
||||||
|
int id,
|
||||||
XApplicationDto item,
|
XApplicationDto item,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -84,12 +84,21 @@ namespace xIdentityService.Providers
|
|||||||
tokens.AccessToken
|
tokens.AccessToken
|
||||||
)
|
)
|
||||||
.ValidateGroupAsync();
|
.ValidateGroupAsync();
|
||||||
|
if (!id.IsValidIntId())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var client = GetRestClient(tokens);
|
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);
|
request.AddJsonBody(item);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -227,7 +236,7 @@ namespace xIdentityService.Providers
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Attach XQuery to Request ...
|
// Attach XQuery to Request ...
|
||||||
request = request.AttachXQuery (query);
|
request = request.AttachXQuery(query);
|
||||||
|
|
||||||
//
|
//
|
||||||
var response = await RunRestRequest<XQueryResult<XApplicationDto>>(
|
var response = await RunRestRequest<XQueryResult<XApplicationDto>>(
|
||||||
@@ -369,11 +378,13 @@ namespace xIdentityService.Providers
|
|||||||
/// Update Specified ApiKey ...
|
/// Update Specified ApiKey ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tokens"></param>
|
/// <param name="tokens"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XApiKeyDto> UpdateApiKey(
|
public async Task<XApiKeyDto> UpdateApiKey(
|
||||||
XTokenResponse tokens,
|
XTokenResponse tokens,
|
||||||
|
Guid id,
|
||||||
XApiKeyDto item,
|
XApiKeyDto item,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -382,12 +393,17 @@ namespace xIdentityService.Providers
|
|||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
await validationProvider
|
await validationProvider
|
||||||
.GroupValidationBuilder()
|
.GroupValidationBuilder()
|
||||||
|
.AddIsGuid(id)
|
||||||
.AddNotNull(item)
|
.AddNotNull(item)
|
||||||
.AddNotNull(tokens)
|
.AddNotNull(tokens)
|
||||||
.AddNotEmpty(
|
.AddNotEmpty(
|
||||||
tokens.AccessToken
|
tokens.AccessToken
|
||||||
)
|
)
|
||||||
.ValidateGroupAsync();
|
.ValidateGroupAsync();
|
||||||
|
if (id != item.Id)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var client = GetRestClient(tokens);
|
var client = GetRestClient(tokens);
|
||||||
@@ -396,7 +412,7 @@ namespace xIdentityService.Providers
|
|||||||
var request = GetRestRequet(
|
var request = GetRestRequet(
|
||||||
XApiAccountEndpoint.UpdateApiKey,
|
XApiAccountEndpoint.UpdateApiKey,
|
||||||
@params: new Dictionary<string, string> {
|
@params: new Dictionary<string, string> {
|
||||||
{ XParam.XId.GetStringValue (), item.Id.ToString() }
|
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
request.AddJsonBody(item);
|
request.AddJsonBody(item);
|
||||||
@@ -442,7 +458,7 @@ namespace xIdentityService.Providers
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Attach XQuery to Request ...
|
// Attach XQuery to Request ...
|
||||||
request = request.AttachXQuery (query);
|
request = request.AttachXQuery(query);
|
||||||
|
|
||||||
//
|
//
|
||||||
var response = await RunRestRequest<XQueryResult<XApiKeyDto>>(
|
var response = await RunRestRequest<XQueryResult<XApiKeyDto>>(
|
||||||
@@ -630,11 +646,13 @@ namespace xIdentityService.Providers
|
|||||||
/// Update Specified Api Key Usage ...
|
/// Update Specified Api Key Usage ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tokens"></param>
|
/// <param name="tokens"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XApiKeyUsageDto> UpdateApiKeyUsage(
|
public async Task<XApiKeyUsageDto> UpdateApiKeyUsage(
|
||||||
XTokenResponse tokens,
|
XTokenResponse tokens,
|
||||||
|
long id,
|
||||||
XApiKeyUsageDto item,
|
XApiKeyUsageDto item,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -649,6 +667,9 @@ namespace xIdentityService.Providers
|
|||||||
tokens.AccessToken
|
tokens.AccessToken
|
||||||
)
|
)
|
||||||
.ValidateGroupAsync();
|
.ValidateGroupAsync();
|
||||||
|
if (id <= 0 || id != item.Id) {
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var client = GetRestClient(tokens);
|
var client = GetRestClient(tokens);
|
||||||
@@ -658,7 +679,7 @@ namespace xIdentityService.Providers
|
|||||||
XApiAccountEndpoint.UpdateApiKeyUsage,
|
XApiAccountEndpoint.UpdateApiKeyUsage,
|
||||||
@params: new Dictionary<string, string>
|
@params: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ XParam.XId.GetStringValue (), item.Id.ToString() }
|
{ XParam.XId.GetStringValue (), id.ToString() }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
request.AddJsonBody(item);
|
request.AddJsonBody(item);
|
||||||
@@ -704,7 +725,7 @@ namespace xIdentityService.Providers
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Attach XQuery to Request ...
|
// Attach XQuery to Request ...
|
||||||
request = request.AttachXQuery (query);
|
request = request.AttachXQuery(query);
|
||||||
|
|
||||||
//
|
//
|
||||||
var response = await RunRestRequest<XQueryResult<XApiKeyUsageDto>>(
|
var response = await RunRestRequest<XQueryResult<XApiKeyUsageDto>>(
|
||||||
@@ -891,7 +912,7 @@ namespace xIdentityService.Providers
|
|||||||
|
|
||||||
//
|
//
|
||||||
var request = GetRestRequet(
|
var request = GetRestRequet(
|
||||||
XApiAccountEndpoint.RemoveApiKey,
|
XApiAccountEndpoint.RemoveApiKeyCustom,
|
||||||
@params: new Dictionary<string, string> {
|
@params: new Dictionary<string, string> {
|
||||||
{ XParam.XApiKeyId.GetStringValue (), apiKeyId.ToString() },
|
{ XParam.XApiKeyId.GetStringValue (), apiKeyId.ToString() },
|
||||||
{ XParam.XApplicationId.GetStringValue (), applicationId.ToString() }
|
{ XParam.XApplicationId.GetStringValue (), applicationId.ToString() }
|
||||||
@@ -1132,7 +1153,7 @@ namespace xIdentityService.Providers
|
|||||||
var client = GetRestClient();
|
var client = GetRestClient();
|
||||||
|
|
||||||
//
|
//
|
||||||
var checksum = SecurityProvider.Encrypt(validationRequest.ToJson()).ToMd5String();
|
var checksum = SecurityProvider.Encrypt(validationRequest.ToJSON()).ToMd5String();
|
||||||
|
|
||||||
//
|
//
|
||||||
var request = GetRestRequet(
|
var request = GetRestRequet(
|
||||||
@@ -1141,6 +1162,7 @@ namespace xIdentityService.Providers
|
|||||||
{ XHeader.ChecksumDigest.GetStringValue(), checksum }
|
{ XHeader.ChecksumDigest.GetStringValue(), checksum }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
request.AddJsonBody(validationRequest);
|
||||||
|
|
||||||
//
|
//
|
||||||
var response = await RunRestRequest<XApiKeyValidationResult>(
|
var response = await RunRestRequest<XApiKeyValidationResult>(
|
||||||
|
|||||||
Reference in New Issue
Block a user