Compare commits
1
Commits
a87ea5d64d
...
c4e430a98f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4e430a98f |
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using xIdentityHelper;
|
||||
using System.Threading;
|
||||
using xCommons.Attributes;
|
||||
@@ -17,6 +18,13 @@ namespace xIds.Controllers
|
||||
{
|
||||
public partial class ApplicationsController
|
||||
{
|
||||
/// <summary>
|
||||
/// Create Api Key ...
|
||||
/// </summary>
|
||||
/// <param name="applicationId"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[RequireXPowered]
|
||||
[Authorize(LocalApi.PolicyName)]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
@@ -56,7 +64,6 @@ namespace xIds.Controllers
|
||||
}
|
||||
|
||||
//
|
||||
// Create Specified Api Key ...
|
||||
var result = await provider.CreateApiKey(
|
||||
userInfo: userInfo,
|
||||
scopes: request.Scopes,
|
||||
@@ -78,6 +85,13 @@ namespace xIds.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Api Key ...
|
||||
/// </summary>
|
||||
/// <param name="apiKeyId"></param>
|
||||
/// <param name="applicationId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[RequireXPowered]
|
||||
[Authorize(LocalApi.PolicyName)]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
@@ -117,7 +131,6 @@ namespace xIds.Controllers
|
||||
}
|
||||
|
||||
//
|
||||
// Create Specified Api Key ...
|
||||
var result = await provider.RemoveApiKeyAsync(
|
||||
id: apiKeyId,
|
||||
softDelete: false,
|
||||
@@ -136,6 +149,14 @@ namespace xIds.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rotate Specified Api Key ...
|
||||
/// </summary>
|
||||
/// <param name="apiKeyId"></param>
|
||||
/// <param name="applicationId"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[RequireXPowered]
|
||||
[Authorize(LocalApi.PolicyName)]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
@@ -192,7 +213,6 @@ namespace xIds.Controllers
|
||||
}
|
||||
|
||||
//
|
||||
// Create Specified Api Key ...
|
||||
var result = await provider.RotateApiKey(
|
||||
apiKeyId: apiKeyId,
|
||||
userInfo: userInfo,
|
||||
@@ -211,19 +231,75 @@ namespace xIds.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Revoke Specified Api Key ...
|
||||
/// </summary>
|
||||
/// <param name="apiKeyId"></param>
|
||||
/// <param name="applicationId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[RequireXPowered]
|
||||
[Authorize(LocalApi.PolicyName)]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
[HttpPost("Applications/{applicationId}/ApiKeys/{apiKeyId}/Revoke")]
|
||||
public async Task<ActionResult<XApiKeyDto>> RevokeApiKey(
|
||||
public async Task<ActionResult<bool>> RevokeApiKey(
|
||||
[FromRoute] Guid apiKeyId,
|
||||
[FromRoute] int applicationId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (
|
||||
apiKeyId.IsDefaultGuid() ||
|
||||
!applicationId.IsValidIntId())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
|
||||
//
|
||||
// Retrieve Application for Validating ...
|
||||
var application = await provider.GetApplicationAsync(
|
||||
id: applicationId,
|
||||
userInfo: userInfo,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true
|
||||
);
|
||||
if (application.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await provider.RevokeApiKey(
|
||||
apiKeyId: apiKeyId,
|
||||
userInfo: userInfo,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Application's Api Keys ...
|
||||
/// </summary>
|
||||
/// <param name="applicationId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[RequireXPowered]
|
||||
[Authorize(LocalApi.PolicyName)]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
@@ -233,33 +309,176 @@ namespace xIds.Controllers
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!applicationId.IsValidIntId())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
|
||||
//
|
||||
// Retrieve Application for Validating ...
|
||||
var application = await provider.GetApplicationAsync(
|
||||
id: applicationId,
|
||||
userInfo: userInfo,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true
|
||||
);
|
||||
if (application.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await provider.GetApplicationApiKeys(
|
||||
userInfo: userInfo,
|
||||
applicationId: applicationId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Api Keys Usages ...
|
||||
/// </summary>
|
||||
/// <param name="apiKeyId"></param>
|
||||
/// <param name="applicationId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[RequireXPowered]
|
||||
[Authorize(LocalApi.PolicyName)]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
[HttpPost("Applications/{applicationId}/ApiKeys/{apiKeyId}/Usages")]
|
||||
public async Task<ActionResult<XApiKeyDto>> GetApiKeyUsages(
|
||||
public async Task<ActionResult<IEnumerable<XApiKeyUsageDto>>> GetApiKeyUsages(
|
||||
[FromRoute] Guid apiKeyId,
|
||||
[FromRoute] int applicationId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[RequireXPowered]
|
||||
[Authorize(LocalApi.PolicyName)]
|
||||
[HttpPost("Applications/{applicationId}/ApiKeys/{apiKeyId}/Validate")]
|
||||
public async Task<ActionResult<XApiKeyDto>> ValidateApiKey(
|
||||
[FromRoute] Guid apiKeyId,
|
||||
[FromRoute] int applicationId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (
|
||||
apiKeyId.IsDefaultGuid() ||
|
||||
!applicationId.IsValidIntId())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
|
||||
//
|
||||
// Retrieve Application for Validating ...
|
||||
var application = await provider.GetApplicationAsync(
|
||||
id: applicationId,
|
||||
userInfo: userInfo,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true
|
||||
);
|
||||
if (application.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve ApiKey for Validating ...
|
||||
var apiKey = await provider.GetApiKeyAsync(
|
||||
id: apiKeyId,
|
||||
userInfo: userInfo,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true
|
||||
);
|
||||
if (application.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await provider.FindManyApiKeyUsageAsync(
|
||||
userInfo: userInfo,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x => x.ApiKeyId == apiKeyId,
|
||||
orderBuilder: x => x.OrderBy(y => y.RequestedOn)
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate Specifed Api Key ...
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[RequireXPowered]
|
||||
[Authorize(LocalApi.PolicyName)]
|
||||
[HttpPost("Applications/ApiKeys/Validate")]
|
||||
public async Task<ActionResult<XApiKeyValidationResult>> ValidateApiKey(
|
||||
[FromBody] XApiKeyValidationRequest request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
await ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotNull(request)
|
||||
.AddNotEmpty(request.ApiKey)
|
||||
.AddNotEmpty(request.ClientIP)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
|
||||
//
|
||||
var result = await provider.ValidateApiKey(
|
||||
userInfo: userInfo,
|
||||
apiKey: request.ApiKey,
|
||||
clientIP: request.ClientIP,
|
||||
requiredScope: request.RequiredScope,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -29,13 +29,15 @@
|
||||
|
||||
<!-- Local Dependencies -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xDashboard.xMessageService" Version="1.0.0" />
|
||||
<PackageReference Include="xDashboard.xStorageService" Version="1.0.0" />
|
||||
<!-- <PackageReference Include="xDashboard.xMessageService" Version="1.0.0" />
|
||||
<PackageReference Include="xDashboard.xStorageService" Version="1.0.0" /> -->
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Project Dependencies -->
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Modules\xIdentityHelper\xIdentityHelper.csproj" />
|
||||
<ProjectReference Include="..\Modules\xMessageService\xMessageService.csproj" />
|
||||
<ProjectReference Include="..\Modules\xStorageService\xStorageService.csproj" />
|
||||
<ProjectReference Include="..\Modules\xIdentityService\xIdentityService.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user