Compare commits
4
Commits
b00391517a
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5085fc54a4 | ||
|
|
2e8f269ae6 | ||
|
|
c4e430a98f | ||
|
|
a87ea5d64d |
@@ -1,9 +1,253 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using System.Threading;
|
||||||
|
using xIdentityHelper;
|
||||||
|
using xCommons.Attributes;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using static IdentityServer4.IdentityServerConstants;
|
||||||
|
|
||||||
namespace xIds.Controllers
|
namespace xIds.Controllers
|
||||||
{
|
{
|
||||||
public partial class ApplicationsController
|
public partial class ApplicationsController
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
#region ApiKey ...
|
#region ApiKey ...
|
||||||
|
/// <summary>
|
||||||
|
/// Get Specified ApiKey ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("ApiKeys/{id}")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApiKeyDto>> GetApiKey(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (id.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.GetApiKeyAsync(
|
||||||
|
id: id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified ApiKey ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpDelete("ApiKeys/{id}")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApiKeyDto>> RemoveApiKey(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (id.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.RemoveApiKeyAsync(
|
||||||
|
id: id,
|
||||||
|
softDelete: false,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Specified ApiKey ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpPut("ApiKeys/{id}")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApiKeyDto>> UpdateApiKey(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
[FromBody] XApiKeyDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
id.IsDefaultGuid() ||
|
||||||
|
!item.IsValidForAdd()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.UpdateApiKeyAsync(
|
||||||
|
id: id,
|
||||||
|
item: item,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get All Specified ApiKeys ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("ApiKeys")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<IEnumerable<XApiKeyDto>>> GetAllApiKeys(
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.GetAllApiKeyAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query ApiKeys ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("ApiKeys/Query")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XQueryResult<XApiKeyDto>>> QueryApiKeys(
|
||||||
|
[FromRoute] XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.QueryApiKeyAsync(
|
||||||
|
query: query,
|
||||||
|
predicate: null,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,299 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using xIdentityHelper;
|
||||||
|
using System.Threading;
|
||||||
|
using xCommons.Attributes;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using static IdentityServer4.IdentityServerConstants;
|
||||||
|
|
||||||
namespace xIds.Controllers
|
namespace xIds.Controllers
|
||||||
{
|
{
|
||||||
public partial class ApplicationsController
|
public partial class ApplicationsController
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
#region ApiKeyUsage ...
|
#region ApiKeyUsage ...
|
||||||
|
/// <summary>
|
||||||
|
/// Add Api Key Usage ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpPost("ApiKeys/Usages")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApiKeyUsageDto>> AddApiKeyUsage(
|
||||||
|
[FromBody] XApiKeyUsageDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (item.IsValidForAdd())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.AddApiKeyUsageAsync(
|
||||||
|
item: item,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get Specified Api Key Usage ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[HttpGet("ApiKeys/Usages/{id}")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApiKeyUsageDto>> GetApiKeyUsage(
|
||||||
|
[FromRoute] long id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (id <= 0)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.GetApiKeyUsageAsync(
|
||||||
|
id: id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified Api Key Usage ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[HttpDelete("ApiKeys/Usages/{id}")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApiKeyUsageDto>> RemoveApiKeyUsage(
|
||||||
|
[FromRoute] long id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (id <= 0)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.RemoveApiKeyUsageAsync(
|
||||||
|
id: id,
|
||||||
|
softDelete: false,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Specified Api Key Usage ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[HttpPut("ApiKeys/Usages/{id}")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApiKeyUsageDto>> UpdateApiKeyUsage(
|
||||||
|
[FromRoute] long id,
|
||||||
|
[FromBody] XApiKeyUsageDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
id <= 0 ||
|
||||||
|
!item.IsValidForAdd()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.UpdateApiKeyUsageAsync(
|
||||||
|
id: id,
|
||||||
|
item: item,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get All Api Key Usages ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("ApiKeys/Usages")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<IEnumerable<XApiKeyUsageDto>>> GetAllApiKeyUsages(
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.GetAllApiKeyUsageAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
orderBuilder: x => x.OrderBy(y => y.RequestedOn)
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Api Key Usages ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[HttpGet("ApiKeys/Usages/Query")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XQueryResult<XApiKeyUsageDto>>> QueryApiKeyUsages(
|
||||||
|
[FromRoute] XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.QueryApiKeyUsageAsync(
|
||||||
|
query: query,
|
||||||
|
predicate: null,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
orderBuilder: x => x.OrderBy(y => y.RequestedOn)
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xModels.Dtos;
|
||||||
using xIdentityHelper;
|
using xIdentityHelper;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using xCommons.Attributes;
|
using xCommons.Attributes;
|
||||||
|
using xCommons.Extensions;
|
||||||
using xIdentityModels.Dtos;
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using static IdentityServer4.IdentityServerConstants;
|
using static IdentityServer4.IdentityServerConstants;
|
||||||
|
|
||||||
@@ -14,17 +20,295 @@ namespace xIds.Controllers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
#region Application ...
|
#region Application ...
|
||||||
[HttpPost]
|
/// <summary>
|
||||||
|
/// Create Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Sample request:
|
||||||
|
///
|
||||||
|
/// {
|
||||||
|
/// "type": 0,
|
||||||
|
/// "name": "string",
|
||||||
|
/// "description": "string",
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("")]
|
||||||
[RequireXPowered]
|
[RequireXPowered]
|
||||||
[Authorize(LocalApi.PolicyName)]
|
[Authorize(LocalApi.PolicyName)]
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
public async Task<ActionResult<XApplicationDto>> CreateApplication(
|
public async Task<ActionResult<XApplicationDto>> CreateApplication(
|
||||||
[FromBody] XApplicationDto request,
|
[FromBody] XApplicationDto item,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
throw new NotImplementedException("");
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!item.IsValidForAdd())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.AddApplicationAsync(
|
||||||
|
item: item,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Specified Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Sample request:
|
||||||
|
///
|
||||||
|
/// {
|
||||||
|
/// "id": 0,
|
||||||
|
/// "type": 0,
|
||||||
|
/// "name": "string",
|
||||||
|
/// "description": "string",
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut("")]
|
||||||
|
[RequireXPowered]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApplicationDto>> UpdateApplication(
|
||||||
|
[FromBody] XApplicationDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!item.IsValidForAdd())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.UpdateApplicationAsync(
|
||||||
|
item: item,
|
||||||
|
id: item.Id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApplicationDto>> RemoveApplication(
|
||||||
|
[FromRoute] int id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!id.IsValidIntId())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.RemoveApplicationAsync(
|
||||||
|
id: id,
|
||||||
|
softDelete: false,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get Specified Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XApplicationDto>> GetApplication(
|
||||||
|
[FromRoute] int id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!id.IsValidIntId())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.GetApplicationAsync(
|
||||||
|
id: id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get All Application ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("")]
|
||||||
|
[RequireXPowered]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<IEnumerable<XApplicationDto>>> GetAllApplications(
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.GetAllApplicationAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
orderBuilder: x => x.OrderBy(y => y.Id)
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Applications ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("Query")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<XQueryResult<XApplicationDto>>> QueryApplications(
|
||||||
|
[FromRoute] XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.QueryApplicationAsync(
|
||||||
|
query: query,
|
||||||
|
predicate: null,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
orderBuilder: x => x.OrderBy(y => y.Id)
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,556 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xIdentityHelper;
|
||||||
|
using System.Threading;
|
||||||
|
using xCommons.Attributes;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using static IdentityServer4.IdentityServerConstants;
|
||||||
|
|
||||||
|
namespace xIds.Controllers
|
||||||
|
{
|
||||||
|
public partial class ApplicationsController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Show 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)]
|
||||||
|
[HttpGet("{applicationId}/ApiKeys/{apiKeyId}/Show")]
|
||||||
|
public async Task<ActionResult<string>> ShowApiKey(
|
||||||
|
[FromRoute] Guid apiKeyId,
|
||||||
|
[FromRoute] int applicationId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
apiKeyId.IsDefaultGuid() ||
|
||||||
|
!applicationId.IsValidIntId())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.ShowApiKey(
|
||||||
|
userInfo: userInfo,
|
||||||
|
apiKeyId: apiKeyId,
|
||||||
|
applicationId: applicationId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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)]
|
||||||
|
[HttpPost("{applicationId}/ApiKeys/Create")]
|
||||||
|
public async Task<ActionResult<XApiKeyDto>> CreateApiKey(
|
||||||
|
[FromRoute] int applicationId,
|
||||||
|
[FromBody] XCreateApiKeyRequest request,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
!request.IsValid() ||
|
||||||
|
!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();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Noramlize TimeSpan ...
|
||||||
|
var expirationTimeSpan = TimeSpan
|
||||||
|
.FromMinutes(apiKeyConfiguration.DefaultExpirationMinutes);
|
||||||
|
if (
|
||||||
|
request.ExpirationMinutes.HasValue &&
|
||||||
|
request.ExpirationMinutes.Value > 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Normalize Expiration Minutes ...
|
||||||
|
int minutes = request.ExpirationMinutes.Value;
|
||||||
|
if (minutes > apiKeyConfiguration.MaxExpirationMinutes)
|
||||||
|
{
|
||||||
|
minutes = apiKeyConfiguration.MaxExpirationMinutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
expirationTimeSpan = TimeSpan.FromMinutes(minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.CreateApiKey(
|
||||||
|
userInfo: userInfo,
|
||||||
|
scopes: request.Scopes,
|
||||||
|
applicationId: applicationId,
|
||||||
|
rateLimit: request.RateLimit,
|
||||||
|
allowedIPs: request.AllowedIPs,
|
||||||
|
expiration: expirationTimeSpan,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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)]
|
||||||
|
[HttpDelete("{applicationId}/ApiKeys/{apiKeyId}")]
|
||||||
|
public async Task<ActionResult<XApiKeyDto>> RemoveApiKey(
|
||||||
|
[FromRoute] Guid apiKeyId,
|
||||||
|
[FromRoute] int applicationId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
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.RemoveApiKeyAsync(
|
||||||
|
id: apiKeyId,
|
||||||
|
softDelete: false,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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)]
|
||||||
|
[HttpPost("{applicationId}/ApiKeys/{apiKeyId}")]
|
||||||
|
public async Task<ActionResult<XApiKeyDto>> RotateApiKey(
|
||||||
|
[FromRoute] Guid apiKeyId,
|
||||||
|
[FromRoute] int applicationId,
|
||||||
|
[FromBody] XRotateApiKeyRequest request,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
apiKeyId.IsDefaultGuid() ||
|
||||||
|
!applicationId.IsValidIntId())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Normalize ...
|
||||||
|
if (
|
||||||
|
request.IsNullOrDefault() ||
|
||||||
|
request.NewExpiration.IsNull() ||
|
||||||
|
!request.NewExpiration.HasValue
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var timeSpan = TimeSpan.FromMinutes(apiKeyConfiguration.DefaultExpirationMinutes);
|
||||||
|
request = new XRotateApiKeyRequest
|
||||||
|
{
|
||||||
|
NewExpiration = timeSpan
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
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.RotateApiKey(
|
||||||
|
apiKeyId: apiKeyId,
|
||||||
|
userInfo: userInfo,
|
||||||
|
newExpiration: request.NewExpiration,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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("{applicationId}/ApiKeys/{apiKeyId}/Revoke")]
|
||||||
|
public async Task<ActionResult<bool>> RevokeApiKey(
|
||||||
|
[FromRoute] Guid apiKeyId,
|
||||||
|
[FromRoute] int applicationId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
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)]
|
||||||
|
[HttpGet("{applicationId}/ApiKeys")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public async Task<ActionResult<IEnumerable<XApiKeyDto>>> GetApiKeys(
|
||||||
|
[FromRoute] int applicationId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
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)]
|
||||||
|
[HttpGet("{applicationId}/ApiKeys/{apiKeyId}/Usages")]
|
||||||
|
public async Task<ActionResult<IEnumerable<XApiKeyUsageDto>>> GetApiKeyUsages(
|
||||||
|
[FromRoute] Guid apiKeyId,
|
||||||
|
[FromRoute] int applicationId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
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]
|
||||||
|
[HttpPost("ApiKeys/Validate")]
|
||||||
|
[Authorize(LocalApi.PolicyName)]
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using xIds.Interfaces;
|
using xIds.Interfaces;
|
||||||
using xCommons.Providers;
|
using xCommons.Providers;
|
||||||
|
using xIds.Configurations;
|
||||||
using xIds.Controllers.Base;
|
using xIds.Controllers.Base;
|
||||||
using xCommons.Configurations;
|
using xCommons.Configurations;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -13,17 +14,25 @@ namespace xIds.Controllers
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public partial class ApplicationsController : XIBaseController
|
public partial class ApplicationsController : XIBaseController
|
||||||
{
|
{
|
||||||
|
private readonly IXApplicationProvider provider;
|
||||||
|
private readonly XApiKeyConfiguration apiKeyConfiguration;
|
||||||
|
|
||||||
public ApplicationsController(
|
public ApplicationsController(
|
||||||
ILogger<ApplicationsController> logger,
|
IXApplicationProvider provider,
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityManager identityManager,
|
IXIdentityManager identityManager,
|
||||||
XValidationProvider validationProvider
|
XAppConfiguration appConfiguration,
|
||||||
|
ILogger<ApplicationsController> logger,
|
||||||
|
XValidationProvider validationProvider,
|
||||||
|
XApiKeyConfiguration apiKeyConfiguration
|
||||||
) : base(
|
) : base(
|
||||||
logger,
|
logger,
|
||||||
appConfiguration,
|
appConfiguration,
|
||||||
identityManager,
|
identityManager,
|
||||||
validationProvider
|
validationProvider
|
||||||
)
|
)
|
||||||
{ }
|
{
|
||||||
|
this.provider = provider;
|
||||||
|
this.apiKeyConfiguration = apiKeyConfiguration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,11 +176,13 @@ namespace xIds.Interfaces
|
|||||||
/// Add Specified Item ...
|
/// Add Specified Item ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
|
/// <param name="apiKey"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XApiKeyDto> AddApiKeyAsync(
|
Task<XApiKeyDto> AddApiKeyAsync(
|
||||||
XApiKeyDto item,
|
XApiKeyDto item,
|
||||||
|
string apiKey = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -480,6 +482,21 @@ namespace xIds.Interfaces
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Custom Actions ...
|
#region Custom Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Show Specifid Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKeyId"></param>
|
||||||
|
/// <param name="applicationId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> ShowApiKey(
|
||||||
|
Guid apiKeyId,
|
||||||
|
int applicationId,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate a New ApiKey and Add It to DB ...
|
/// Generate a New ApiKey and Add It to DB ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using IdentityServer4.Extensions;
|
|||||||
using xIdentityModels.Extensions;
|
using xIdentityModels.Extensions;
|
||||||
using Microsoft.EntityFrameworkCore.Query;
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using AutoMapper;
|
||||||
|
|
||||||
namespace xIds.Providers
|
namespace xIds.Providers
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,7 @@ namespace xIds.Providers
|
|||||||
private readonly IXIdentityManager identityManager;
|
private readonly IXIdentityManager identityManager;
|
||||||
private readonly XDataServiceConfiguration configuration;
|
private readonly XDataServiceConfiguration configuration;
|
||||||
private readonly XApiKeyConfiguration apiKeyConfiguration;
|
private readonly XApiKeyConfiguration apiKeyConfiguration;
|
||||||
|
private readonly Action<IMapperConfigurationExpression> mapperConfigurationExp;
|
||||||
|
|
||||||
public XApplicationProvider(
|
public XApplicationProvider(
|
||||||
IMemoryCache cache,
|
IMemoryCache cache,
|
||||||
@@ -45,6 +47,23 @@ namespace xIds.Providers
|
|||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.identityManager = identityManager;
|
this.identityManager = identityManager;
|
||||||
this.apiKeyConfiguration = apiKeyConfiguration;
|
this.apiKeyConfiguration = apiKeyConfiguration;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Configure Mapper Options ...
|
||||||
|
mapperConfigurationExp = cfg =>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
cfg.CreateMap<XApiKey, XApiKeyDto>()
|
||||||
|
.ReverseMap();
|
||||||
|
|
||||||
|
//
|
||||||
|
cfg.CreateMap<XApplication, XApplicationDto>()
|
||||||
|
.ReverseMap();
|
||||||
|
|
||||||
|
//
|
||||||
|
cfg.CreateMap<XApiKeyUsage, XApiKeyUsageDto>()
|
||||||
|
.ReverseMap();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -305,7 +324,8 @@ namespace xIds.Providers
|
|||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
if (currentCount >= limitPerMinute) {
|
if (currentCount >= limitPerMinute)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ namespace xIds.Providers
|
|||||||
/// Add Specified Item ...
|
/// Add Specified Item ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
|
/// <param name="apiKey"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XApiKeyDto> AddApiKeyAsync(
|
public async Task<XApiKeyDto> AddApiKeyAsync(
|
||||||
XApiKeyDto item,
|
XApiKeyDto item,
|
||||||
|
string apiKey = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -85,7 +87,12 @@ namespace xIds.Providers
|
|||||||
item.CreatedOn = DateTime.UtcNow;
|
item.CreatedOn = DateTime.UtcNow;
|
||||||
|
|
||||||
//
|
//
|
||||||
var entity = item.MapConvert<XApiKey, XApiKeyDto>();
|
var entity = item.MapConvert<XApiKey, XApiKeyDto>(mapperConfigurationExp);
|
||||||
|
if (!apiKey.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
entity.Key = apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
var entry = await dbContext.ApiKeys.AddAsync(
|
var entry = await dbContext.ApiKeys.AddAsync(
|
||||||
entity: entity,
|
entity: entity,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
@@ -170,7 +177,14 @@ namespace xIds.Providers
|
|||||||
exists = exists.UpdateData(
|
exists = exists.UpdateData(
|
||||||
updateWith: item,
|
updateWith: item,
|
||||||
propertyWhiteList: [],
|
propertyWhiteList: [],
|
||||||
propertyBlackList: []
|
propertyBlackList: [
|
||||||
|
nameof(XApiKey.Id),
|
||||||
|
nameof(XApiKey.KeyHash),
|
||||||
|
nameof(XApiKey.KeyPrefix),
|
||||||
|
nameof(XApiKey.CreatedOn),
|
||||||
|
nameof(XApiKey.Application),
|
||||||
|
nameof(XApiKey.ApplicationId),
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ namespace xIds.Providers
|
|||||||
updateWith: item,
|
updateWith: item,
|
||||||
propertyWhiteList: [],
|
propertyWhiteList: [],
|
||||||
propertyBlackList: [
|
propertyBlackList: [
|
||||||
|
nameof(XApiKeyUsage.Id),
|
||||||
|
nameof(XApiKeyUsage.ApiKeyId),
|
||||||
nameof(XApiKeyUsage.ResponseTimeMs),
|
nameof(XApiKeyUsage.ResponseTimeMs),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -138,7 +138,9 @@ namespace xIds.Providers
|
|||||||
updateWith: item,
|
updateWith: item,
|
||||||
propertyWhiteList: [],
|
propertyWhiteList: [],
|
||||||
propertyBlackList: [
|
propertyBlackList: [
|
||||||
|
nameof(XApiKey.Id),
|
||||||
nameof(XApplication.ApiKeys),
|
nameof(XApplication.ApiKeys),
|
||||||
|
nameof(XApplication.CreatedOn),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,67 @@ namespace xIds.Providers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
#region Custom Actions ...
|
#region Custom Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Show Specifid Api Key ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKeyId"></param>
|
||||||
|
/// <param name="applicationId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<string> ShowApiKey(
|
||||||
|
Guid apiKeyId,
|
||||||
|
int applicationId,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
apiKeyId.IsDefaultGuid() ||
|
||||||
|
userInfo.IsNullOrDefault() ||
|
||||||
|
!applicationId.IsValidIntId()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Application Exists ...
|
||||||
|
var application = await GetApplicationAsync(
|
||||||
|
id: applicationId,
|
||||||
|
userInfo: userInfo,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (application.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Owner ...
|
||||||
|
if (!IsOwned(application, userInfo))
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve ApiKey Entity ...
|
||||||
|
// Since ApiKey is Only Exists on ApiKey Entity ...
|
||||||
|
var entity = await dbContext.ApiKeys
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == apiKeyId);
|
||||||
|
if (entity.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return entity.Key;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate a New ApiKey and Add It to DB ...
|
/// Generate a New ApiKey and Add It to DB ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -114,6 +175,7 @@ namespace xIds.Providers
|
|||||||
// Add Item to Database ...
|
// Add Item to Database ...
|
||||||
result = await AddApiKeyAsync(
|
result = await AddApiKeyAsync(
|
||||||
item: result,
|
item: result,
|
||||||
|
apiKey: plainKey,
|
||||||
userInfo: userInfo,
|
userInfo: userInfo,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -371,7 +433,7 @@ namespace xIds.Providers
|
|||||||
.ParseListString<string>();
|
.ParseListString<string>();
|
||||||
var allowedScopes = (keyModel.AllowedScopes ?? string.Empty)
|
var allowedScopes = (keyModel.AllowedScopes ?? string.Empty)
|
||||||
.FromJSON<IEnumerable<string>>();
|
.FromJSON<IEnumerable<string>>();
|
||||||
result.Scopes = [..allowedScopes];
|
result.Scopes = [.. allowedScopes];
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check Application is Exists and Active ...
|
// Check Application is Exists and Active ...
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace xIds.Providers
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result = source.MapConvert<XApiKeyDto, XApiKey>();
|
var result = source.MapConvert<XApiKeyDto, XApiKey>(mapperConfigurationExp);
|
||||||
result = await EnrichAsync(
|
result = await EnrichAsync(
|
||||||
source: result,
|
source: result,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
@@ -88,7 +88,7 @@ namespace xIds.Providers
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result = source.MapConvert<XApiKeyUsageDto, XApiKeyUsage>();
|
var result = source.MapConvert<XApiKeyUsageDto, XApiKeyUsage>(mapperConfigurationExp);
|
||||||
result = await EnrichAsync(
|
result = await EnrichAsync(
|
||||||
source: result,
|
source: result,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
@@ -110,7 +110,7 @@ namespace xIds.Providers
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result = source.MapConvert<XApplicationDto, XApplication>();
|
var result = source.MapConvert<XApplicationDto, XApplication>(mapperConfigurationExp);
|
||||||
result = await EnrichAsync(
|
result = await EnrichAsync(
|
||||||
source: result,
|
source: result,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
|
|||||||
+4
-1
@@ -67,7 +67,10 @@ namespace xIds
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Register Authentication ...
|
// Register Authentication ...
|
||||||
services.AddXIdentityServerAuthentication(Configuration);
|
services.AddXIdentityServerAuthentication(
|
||||||
|
configuration: Configuration,
|
||||||
|
addApiKeyAuthentication: true
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register Authorization ...
|
// Register Authorization ...
|
||||||
|
|||||||
@@ -37,12 +37,12 @@
|
|||||||
"MaxFileSize": 41943040
|
"MaxFileSize": 41943040
|
||||||
},
|
},
|
||||||
"ApiKeyConfiguration": {
|
"ApiKeyConfiguration": {
|
||||||
"ApiPrefix": "xapp",
|
"ApiKeyPrefix": "xapp",
|
||||||
"DefaultRateLimit": 60,
|
"DefaultRateLimit": 60,
|
||||||
"EnableAuditLog": false,
|
"EnableAuditLog": false,
|
||||||
"MaxKeysPerApplication": "10",
|
"MaxKeysPerApplication": 10,
|
||||||
"MaxExpirationMinutes": "525600",
|
"MaxExpirationMinutes": 525600,
|
||||||
"DefaultExpirationMinutes": "43200"
|
"DefaultExpirationMinutes": 43200
|
||||||
},
|
},
|
||||||
"DbSeeder": {
|
"DbSeeder": {
|
||||||
"UpdateExists": false,
|
"UpdateExists": false,
|
||||||
|
|||||||
+4
-2
@@ -29,13 +29,15 @@
|
|||||||
|
|
||||||
<!-- Local Dependencies -->
|
<!-- Local Dependencies -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="xDashboard.xMessageService" Version="1.0.0" />
|
<!-- <PackageReference Include="xDashboard.xMessageService" Version="1.0.0" />
|
||||||
<PackageReference Include="xDashboard.xStorageService" Version="1.0.0" />
|
<PackageReference Include="xDashboard.xStorageService" Version="1.0.0" /> -->
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Project Dependencies -->
|
<!-- Project Dependencies -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Modules\xIdentityHelper\xIdentityHelper.csproj" />
|
<ProjectReference Include="..\Modules\xIdentityHelper\xIdentityHelper.csproj" />
|
||||||
|
<ProjectReference Include="..\Modules\xMessageService\xMessageService.csproj" />
|
||||||
|
<ProjectReference Include="..\Modules\xStorageService\xStorageService.csproj" />
|
||||||
<ProjectReference Include="..\Modules\xIdentityService\xIdentityService.csproj" />
|
<ProjectReference Include="..\Modules\xIdentityService\xIdentityService.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user