diff --git a/Controllers/XAccountControllerBase.cs b/Controllers/XAccountControllerBase.cs
index e29fc04..d745be8 100644
--- a/Controllers/XAccountControllerBase.cs
+++ b/Controllers/XAccountControllerBase.cs
@@ -1,23 +1,24 @@
using System;
using System.Linq;
using xModels.Dtos;
+using System.Threading;
using xCommons.Providers;
using xCommons.Extensions;
using xCommons.Attributes;
+using xIdentityModels.Dtos;
using xExceptions.Constants;
using System.Threading.Tasks;
using xIdentityModels.Models;
using xCommons.Configurations;
using Microsoft.AspNetCore.Mvc;
+using xIdentityModels.Constants;
+using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using xIdentityService.Interfaces;
+using xIdentityModels.Navigations;
using Microsoft.Extensions.Logging;
using xIdentityService.Controllers;
using Microsoft.AspNetCore.Authorization;
-using xIdentityModels.Dtos;
-using xIdentityModels.Navigations;
-using xIdentityModels.Constants;
-using Microsoft.AspNetCore.Http;
using static xIdentityHelper.XApiScopeHelper;
namespace xIdentityHelper.Controllers
@@ -1977,5 +1978,1008 @@ namespace xIdentityHelper.Controllers
}
}
#endregion
+
+ //
+ #region Applications ...
+ //
+ #region Application ...
+ ///
+ /// Create Application ...
+ ///
+ ///
+ /// Sample request:
+ ///
+ /// {
+ /// "type": 0,
+ /// "name": "string",
+ /// "description": "string",
+ /// }
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpPost("Applications")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task> CreateApplication(
+ [FromBody] XApplicationDto item,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.CreateApplication(
+ item: item,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Update Specified Application ...
+ ///
+ ///
+ /// Sample request:
+ ///
+ /// {
+ /// "id": 0,
+ /// "type": 0,
+ /// "name": "string",
+ /// "description": "string",
+ /// }
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpPut("Applications/{id}")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task> UpdateApplication(
+ [FromRoute] int id,
+ [FromBody] XApplicationDto item,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.UpdateApplication(
+ id: id,
+ item: item,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Remove Specified Application ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpDelete("Applications/{id}")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task> RemoveApplication(
+ [FromRoute] int id,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.RemoveApplication(
+ id: id,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Get Specified Application ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpGet("Applications/{id}")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task> GetApplication(
+ [FromRoute] int id,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.GetApplication(
+ id: id,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Get All Application ...
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpGet("Applications")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task>> GetAllApplications(
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.GetAllApplications(
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Query Applications ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpGet("Applications/Query")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task>> QueryApplications(
+ [FromRoute] XQuery query,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.QueryApplications(
+ query: query,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+ #endregion
+
+ //
+ #region ApiKey ...
+ ///
+ /// Get Specified ApiKey ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpGet("Applications/ApiKeys/{id}")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task> GetApiKey(
+ [FromRoute] Guid id,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.GetApiKey(
+ id: id,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Remove Specified ApiKey ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpDelete("Applications/ApiKeys/{id}")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task> RemoveApiKey(
+ [FromRoute] Guid id,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.RemoveApiKey(
+ id: id,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Update Specified ApiKey ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpPut("Applications/ApiKeys/{id}")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task> UpdateApiKey(
+ [FromRoute] Guid id,
+ [FromBody] XApiKeyDto item,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.UpdateApiKey(
+ id: id,
+ item: item,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Get All Specified ApiKeys ...
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpGet("Applications/ApiKeys")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task>> GetAllApiKeys(
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.GetAllApiKeys(
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Query ApiKeys ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpGet("Applications/ApiKeys/Query")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task>> QueryApiKeys(
+ [FromRoute] XQuery query,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.QueryApiKeys(
+ query: query,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+ #endregion
+
+ //
+ #region ApiKeyUsage ...
+ ///
+ /// Add Api Key Usage ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpPost("Applications/ApiKeys/Usages")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task> AddApiKeyUsage(
+ [FromBody] XApiKeyUsageDto item,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.AddApiKeyUsage(
+ item: item,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Get Specified Api Key Usage ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpGet("Applications/ApiKeys/Usages/{id}")]
+ public virtual async Task> GetApiKeyUsage(
+ [FromRoute] long id,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.GetApiKeyUsage(
+ id: id,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Remove Specified Api Key Usage ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpDelete("Applications/ApiKeys/Usages/{id}")]
+ public virtual async Task> RemoveApiKeyUsage(
+ [FromRoute] long id,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.RemoveApiKeyUsage(
+ id: id,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Update Specified Api Key Usage ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpPut("Applications/ApiKeys/Usages/{id}")]
+ public virtual async Task> UpdateApiKeyUsage(
+ [FromRoute] long id,
+ [FromBody] XApiKeyUsageDto item,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.UpdateApiKeyUsage(
+ id: id,
+ item: item,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Get All Api Key Usages ...
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpGet("Applications/ApiKeys/Usages")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual async Task>> GetAllApiKeyUsages(
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.GetAllApiKeyUsages(
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Query Api Key Usages ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpGet("Applications/ApiKeys/Usages/Query")]
+ public virtual async Task>> QueryApiKeyUsages(
+ [FromRoute] XQuery query,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.QueryApiKeyUsages(
+ query: query,
+ tokens: tokens,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+ #endregion
+
+ //
+ #region Custom ...
+ ///
+ /// Show Api Key ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpGet("Applications/{applicationId}/ApiKeys/{apiKeyId}/Show")]
+ public virtual async Task> ShowApiKey(
+ [FromRoute] Guid apiKeyId,
+ [FromRoute] int applicationId,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.ShowApiKey(
+ tokens: tokens,
+ apiKeyId: apiKeyId,
+ applicationId: applicationId,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result);
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Create Api Key ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpPost("Applications/{applicationId}/ApiKeys/Create")]
+ public virtual async Task> CreateApiKey(
+ [FromRoute] int applicationId,
+ [FromBody] XCreateApiKeyRequest request,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.CreateApiKey(
+ tokens: tokens,
+ request: request,
+ applicationId: applicationId,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Remove Specified Api Key ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpDelete("Applications/{applicationId}/ApiKeys/{apiKeyId}")]
+ public virtual async Task> RemoveApiKey(
+ [FromRoute] Guid apiKeyId,
+ [FromRoute] int applicationId,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.RemoveApiKey(
+ tokens: tokens,
+ apiKeyId: apiKeyId,
+ applicationId: applicationId,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Rotate Specified Api Key ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpPost("Applications/{applicationId}/ApiKeys/{apiKeyId}")]
+ public virtual async Task> RotateApiKey(
+ [FromRoute] Guid apiKeyId,
+ [FromRoute] int applicationId,
+ [FromBody] XRotateApiKeyRequest request,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.RotateApiKey(
+ tokens: tokens,
+ request: request,
+ apiKeyId: apiKeyId,
+ applicationId: applicationId,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Revoke Specified Api Key ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpPost("Applications/{applicationId}/ApiKeys/{apiKeyId}/Revoke")]
+ public virtual async Task> RevokeApiKey(
+ [FromRoute] Guid apiKeyId,
+ [FromRoute] int applicationId,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.RevokeApiKey(
+ tokens: tokens,
+ apiKeyId: apiKeyId,
+ applicationId: applicationId,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Retrieve Specified Application's Api Keys ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpGet("Applications/{applicationId}/ApiKeys")]
+ public virtual async Task>> GetApiKeys(
+ [FromRoute] int applicationId,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.GetApiKeys(
+ tokens: tokens,
+ applicationId: applicationId,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Retrieve Specified Api Keys Usages ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ [HttpGet("Applications/{applicationId}/ApiKeys/{apiKeyId}/Usages")]
+ public virtual async Task>> GetApiKeyUsages(
+ [FromRoute] Guid apiKeyId,
+ [FromRoute] int applicationId,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var tokens = await RetrieveTokensAsXTokenResponse();
+ var result = await IdentityProvider.GetApiKeyUsages(
+ tokens: tokens,
+ apiKeyId: apiKeyId,
+ applicationId: applicationId,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+
+ ///
+ /// Validate Specifed Api Key ...
+ ///
+ ///
+ ///
+ ///
+ [RequireXPowered]
+ [HttpPost("Applications/ApiKeys/Validate")]
+ public virtual async Task> ValidateApiKey(
+ [FromBody] XApiKeyValidationRequest request,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //
+ // Do Action ...
+ try
+ {
+ //
+ var result = await IdentityProvider.ValidateApiKey(
+ request: request,
+ cancellationToken: cancellationToken
+ );
+
+ //
+ return Ok(result
+ .ToDynamicObject());
+ }
+ catch (Exception ex)
+ {
+ //
+ var exception = GetExceptionActionResult(ex);
+ return exception;
+ }
+ }
+ #endregion
+ #endregion
}
}
\ No newline at end of file
diff --git a/Controllers/XTestIdentityControllerBase.cs b/Controllers/XTestIdentityControllerBase.cs
new file mode 100644
index 0000000..00d8508
--- /dev/null
+++ b/Controllers/XTestIdentityControllerBase.cs
@@ -0,0 +1,194 @@
+using System.Linq;
+using xCommons.Providers;
+using xCommons.Attributes;
+using xCommons.Configurations;
+using Microsoft.AspNetCore.Mvc;
+using xIdentityService.Interfaces;
+using Microsoft.Extensions.Logging;
+using xIdentityService.Controllers;
+using Microsoft.AspNetCore.Authorization;
+
+namespace xIdentityHelper.Controllers
+{
+ public abstract class XTestIdentityControllerBase : XBaseTestIdentityController
+ {
+ protected XTestIdentityControllerBase(
+ ILogger logger,
+ XAppConfiguration appConfiguration,
+ IXIdentityProvider identityProvider,
+ XValidationProvider validationProvider
+ ) : base(logger, appConfiguration, identityProvider, validationProvider)
+ { }
+
+ //
+ #region Identity Actions ...
+ ///
+ /// API Read Scope ...
+ ///
+ /// string message
+ [RequireXPowered]
+ [HttpGet("PassReadAccess")]
+ [Authorize(Policy = XPolicies.ReadAccess)]
+ public virtual ActionResult PassReadAccess()
+ {
+ return Ok("Read Access Passed ...");
+ }
+
+ ///
+ /// API Write Scope ...
+ ///
+ /// string message
+ [RequireXPowered]
+ [HttpGet("PassWriteAccess")]
+ [Authorize(Policy = XPolicies.WriteAccess)]
+ public virtual ActionResult PassWriteAccess()
+ {
+ return Ok("Write Access Passed ...");
+ }
+
+ ///
+ /// API Admin Scope ...
+ ///
+ /// string message
+ [RequireXPowered]
+ [HttpGet("PassAdminAccess")]
+ [Authorize(Policy = XPolicies.AdminAccess)]
+ public virtual ActionResult PassAdminAccess()
+ {
+ return Ok("Admin Access Passed ...");
+ }
+
+ ///
+ /// API Manage Scope ...
+ ///
+ /// string message
+ [RequireXPowered]
+ [HttpGet("PassManageAccess")]
+ [Authorize(Policy = XPolicies.ManageAccess)]
+ public virtual ActionResult PassManageAccess()
+ {
+ return Ok("Manage Access Passed ...");
+ }
+
+ ///
+ /// a simple Action which returns a List of Authenticated User Claims ...
+ ///
+ /// string message which represent current user's claims
+ [RequireXPowered]
+ [HttpGet("HiClaims")]
+ [Authorize(Policy = XPolicies.User)]
+ public virtual ActionResult HiClaims()
+ {
+ //
+ var result = new
+ {
+ name = User.Identity.Name,
+ claims = User.Claims.Select(c => new
+ {
+ c.Type,
+ c.Value
+ })
+ };
+
+ //
+ return Ok(result);
+ }
+
+ ///
+ /// a simple Hello User for Checking Authentication and Policy ...
+ ///
+ /// string message which contains authenticated user name
+ [RequireXPowered]
+ [HttpGet("HiUser")]
+ [Authorize(Policy = XPolicies.User)]
+ public virtual ActionResult HiUser()
+ {
+ //
+ var result = $"Hi User: {User.Identity.Name} ...";
+
+ //
+ return Ok(result);
+ }
+
+ ///
+ /// a simple Hello User for Checking Authentication and Policy ...
+ ///
+ /// string message which contains authenticated user name
+ [RequireXPowered]
+ [HttpGet("HiEnabledUser")]
+ [Authorize(Policy = XPolicies.EnabledUser)]
+ public virtual ActionResult HiEnabledUser()
+ {
+ //
+ var result = $"Hi User: {User.Identity.Name} is Enabled ...";
+
+ //
+ return Ok(result);
+ }
+
+ ///
+ /// a simple Hello User for Checking Authentication and Policy ...
+ ///
+ /// string message which contains authenticated user name
+ [RequireXPowered]
+ [HttpGet("HiAgent")]
+ [Authorize(Policy = XPolicies.Agent)]
+ public virtual ActionResult HiAgent()
+ {
+ //
+ var result = $"Hi Agent: {User.Identity.Name} ...";
+
+ //
+ return Ok(result);
+ }
+
+ ///
+ /// a simple Hello User for Checking Authentication and Policy ...
+ ///
+ /// string message which contains authenticated user name
+ [RequireXPowered]
+ [HttpGet("HiEnabledAgent")]
+ [Authorize(Policy = XPolicies.EnabledAgent)]
+ public virtual ActionResult HiEnabledAgent()
+ {
+ //
+ var result = $"Hi Agent: {User.Identity.Name} is Enabled ...";
+
+ //
+ return Ok(result);
+ }
+
+ ///
+ /// a simple Hello User for Checking Authentication and Policy ...
+ ///
+ /// string message which contains authenticated user name
+ [RequireXPowered]
+ [HttpGet("HiAdmin")]
+ [Authorize(Policy = XPolicies.Admin)]
+ public virtual ActionResult HiAdmin()
+ {
+ //
+ var result = $"Hi Admin: {User.Identity.Name} ...";
+
+ //
+ return Ok(result);
+ }
+
+ ///
+ /// a simple Hello User for Checking Authentication and Policy ...
+ ///
+ /// string message which contains authenticated user name
+ [RequireXPowered]
+ [HttpGet("HiEnabledAdmin")]
+ [Authorize(Policy = XPolicies.EnabledAdmin)]
+ public virtual ActionResult HiEnabledAdmin()
+ {
+ //
+ var result = $"Hi Admin: {User.Identity.Name} is Enabled ...";
+
+ //
+ return Ok(result);
+ }
+ #endregion
+ }
+}
\ No newline at end of file