Refactor and Test Application Controller and ApiKey Access Authorization Handling ...

This commit is contained in:
2026-10-17 01:18:14 +03:30
parent 6b648ede44
commit 9fb70e14d7
5 changed files with 94 additions and 18 deletions
@@ -18,6 +18,8 @@ namespace xIds.Controllers
{
public partial class ApplicationsController
{
//
#region Custom ...
/// <summary>
/// Show Api Key ...
/// </summary>
@@ -510,6 +512,7 @@ namespace xIds.Controllers
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[AllowAnonymous]
[RequireXPowered]
[HttpPost("ApiKeys/Validate")]
[Authorize(LocalApi.PolicyName)]
@@ -532,6 +535,19 @@ namespace xIds.Controllers
//
var userInfo = await GetUserInfo();
var checksum = GetRequestChecksum();
if (checksum.IsNullOrEmpty())
{
XException.NotAuthorized.Throw();
}
//
// Validate Checksum ...
var requestChecksum = securityProvider.Encrypt(request.ToJSON()).ToMd5String();
if (checksum.ToNormalString() != requestChecksum.ToNormalString())
{
XException.NotAuthorized.Throw();
}
//
var result = await provider.ValidateApiKey(
@@ -552,5 +568,6 @@ namespace xIds.Controllers
return result;
}
}
#endregion
}
}