last ...
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
using xExceptions.Attributes;
|
||||||
|
|
||||||
|
namespace xIdentityService.Constants
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// All Available Headers ...
|
||||||
|
/// </summary>
|
||||||
|
public enum XHeader
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Hub Connection ID Header Keys ...
|
||||||
|
/// </summary>
|
||||||
|
[StringValue("ConnectionId")]
|
||||||
|
ConnectionId,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.ObjectPool;
|
||||||
using xCommons.Configurations;
|
using xCommons.Configurations;
|
||||||
using xCommons.Constants;
|
using xCommons.Constants;
|
||||||
using xCommons.Controllers;
|
using xCommons.Controllers;
|
||||||
@@ -11,27 +12,54 @@ using xCommons.Providers;
|
|||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xIdentityModels.Constants;
|
using xIdentityModels.Constants;
|
||||||
using xIdentityModels.Models;
|
using xIdentityModels.Models;
|
||||||
|
using xIdentityService.Constants;
|
||||||
using xIdentityService.Interfaces;
|
using xIdentityService.Interfaces;
|
||||||
|
|
||||||
namespace xIdentityService.Controllers {
|
namespace xIdentityService.Controllers
|
||||||
public abstract class XIBaseController : XBaseController {
|
{
|
||||||
|
public abstract class XIBaseController : XBaseController
|
||||||
|
{
|
||||||
private readonly IXIdentityProvider identityProvider;
|
private readonly IXIdentityProvider identityProvider;
|
||||||
|
|
||||||
public XIBaseController (
|
public XIBaseController(
|
||||||
ILogger logger,
|
ILogger logger,
|
||||||
XAppConfiguration appConfiguration,
|
XAppConfiguration appConfiguration,
|
||||||
IXIdentityProvider identityProvider,
|
IXIdentityProvider identityProvider,
|
||||||
XValidationProvider validationProvider
|
XValidationProvider validationProvider
|
||||||
) : base (
|
) : base(
|
||||||
logger,
|
logger,
|
||||||
appConfiguration,
|
appConfiguration,
|
||||||
validationProvider
|
validationProvider
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
this.identityProvider = identityProvider;
|
this.identityProvider = identityProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
#region User Handlers NonActions ...
|
#region NonActions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Connection ID for Hubs ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string GetConnectionId()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = "";
|
||||||
|
|
||||||
|
//
|
||||||
|
var headerKey = XHeader.ConnectionId.GetStringValue();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check if Connection ID is Provided ...
|
||||||
|
if (Request.Headers.ContainsKey(headerKey))
|
||||||
|
{
|
||||||
|
result = Request.Headers[headerKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve User Identifier Base on XActionRequest
|
/// Retrieve User Identifier Base on XActionRequest
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -40,16 +68,18 @@ namespace xIdentityService.Controllers {
|
|||||||
/// <param name="excludes"></param>
|
/// <param name="excludes"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public string GetUserSelectByParam (
|
public string GetUserSelectByParam(
|
||||||
XActionRequest model,
|
XActionRequest model,
|
||||||
bool forceNotNull = true,
|
bool forceNotNull = true,
|
||||||
ICollection<XUserSelectBy> excludes = null) {
|
ICollection<XUserSelectBy> excludes = null
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
ValidationProvider.NotNull (model);
|
ValidationProvider.NotNull(model);
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = identityProvider.GetUserSelectByParam (
|
var result = identityProvider.GetUserSelectByParam(
|
||||||
model,
|
model,
|
||||||
forceNotNull,
|
forceNotNull,
|
||||||
excludes);
|
excludes);
|
||||||
@@ -63,22 +93,25 @@ namespace xIdentityService.Controllers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public async Task<string> GetAccessToken () {
|
public async Task<string> GetAccessToken()
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var accessToken = Request.Headers[XAuthorization.Header]
|
var accessToken = Request.Headers[XAuthorization.Header]
|
||||||
.ToString ();
|
.ToString();
|
||||||
if (accessToken.IsNullOrEmpty ()) {
|
if (accessToken.IsNullOrEmpty())
|
||||||
|
{
|
||||||
accessToken = await HttpContext
|
accessToken = await HttpContext
|
||||||
.GetTokenAsync (XAuthorization.AccessToken);
|
.GetTokenAsync(XAuthorization.AccessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
if (accessToken
|
if (accessToken
|
||||||
.ToNormalString ()
|
.ToNormalString()
|
||||||
.Contains (XAuthorization.TokenIdentifier
|
.Contains(XAuthorization.TokenIdentifier
|
||||||
.ToNormalString ())) {
|
.ToNormalString()))
|
||||||
|
{
|
||||||
accessToken = accessToken
|
accessToken = accessToken
|
||||||
.Remove (0, XAuthorization.TokenIdentifier.Length);
|
.Remove(0, XAuthorization.TokenIdentifier.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -90,13 +123,15 @@ namespace xIdentityService.Controllers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public async Task<string> GetRefreshToken () {
|
public async Task<string> GetRefreshToken()
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var refreshToken = Request.Headers[XAuthorization.RefreshToken]
|
var refreshToken = Request.Headers[XAuthorization.RefreshToken]
|
||||||
.ToString ();
|
.ToString();
|
||||||
if (refreshToken.IsNullOrEmpty ()) {
|
if (refreshToken.IsNullOrEmpty())
|
||||||
|
{
|
||||||
refreshToken = await HttpContext
|
refreshToken = await HttpContext
|
||||||
.GetTokenAsync (XAuthorization.RefreshToken);
|
.GetTokenAsync(XAuthorization.RefreshToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -108,17 +143,19 @@ namespace xIdentityService.Controllers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public async Task<long> GetTokenExpiresAt () {
|
public async Task<long> GetTokenExpiresAt()
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var expiresAtStr = Request.Headers[XAuthorization.ExpiresAt]
|
var expiresAtStr = Request.Headers[XAuthorization.ExpiresAt]
|
||||||
.ToString ();
|
.ToString();
|
||||||
if (expiresAtStr.IsNullOrEmpty ()) {
|
if (expiresAtStr.IsNullOrEmpty())
|
||||||
|
{
|
||||||
expiresAtStr = await HttpContext
|
expiresAtStr = await HttpContext
|
||||||
.GetTokenAsync (XAuthorization.ExpiresAt);
|
.GetTokenAsync(XAuthorization.ExpiresAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var expiresAt = expiresAtStr.ConvertTo<long> ();
|
var expiresAt = expiresAtStr.ConvertTo<long>();
|
||||||
|
|
||||||
//
|
//
|
||||||
return expiresAt;
|
return expiresAt;
|
||||||
@@ -129,17 +166,19 @@ namespace xIdentityService.Controllers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public async Task<XLoginResponse> RetrieveTokensAsXLoginResponse () {
|
public async Task<XLoginResponse> RetrieveTokensAsXLoginResponse()
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var accessToken = await GetAccessToken ();
|
var accessToken = await GetAccessToken();
|
||||||
var refreshToken = await GetRefreshToken ();
|
var refreshToken = await GetRefreshToken();
|
||||||
var expiresAt = await GetTokenExpiresAt ();
|
var expiresAt = await GetTokenExpiresAt();
|
||||||
|
|
||||||
//
|
//
|
||||||
return new XLoginResponse {
|
return new XLoginResponse
|
||||||
|
{
|
||||||
AccessToken = accessToken,
|
AccessToken = accessToken,
|
||||||
RefreshToken = refreshToken,
|
RefreshToken = refreshToken,
|
||||||
ExpiresAt = expiresAt
|
ExpiresAt = expiresAt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,17 +187,19 @@ namespace xIdentityService.Controllers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public async Task<XTokenResponse> RetrieveTokensAsXTokenResponse () {
|
public async Task<XTokenResponse> RetrieveTokensAsXTokenResponse()
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var accessToken = await GetAccessToken ();
|
var accessToken = await GetAccessToken();
|
||||||
var refreshToken = await GetRefreshToken ();
|
var refreshToken = await GetRefreshToken();
|
||||||
var expiresAt = await GetTokenExpiresAt ();
|
var expiresAt = await GetTokenExpiresAt();
|
||||||
|
|
||||||
//
|
//
|
||||||
return new XTokenResponse {
|
return new XTokenResponse
|
||||||
|
{
|
||||||
AccessToken = accessToken,
|
AccessToken = accessToken,
|
||||||
RefreshToken = refreshToken,
|
RefreshToken = refreshToken,
|
||||||
ExpiresAt = expiresAt
|
ExpiresAt = expiresAt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,15 +208,17 @@ namespace xIdentityService.Controllers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public async Task<XUserClaimsInfoDto> GetUserInfo () {
|
public async Task<XUserClaimsInfoDto> GetUserInfo()
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var claims = User.Claims ?? null;
|
var claims = User.Claims ?? null;
|
||||||
if (!claims.HasChild ()) {
|
if (!claims.HasChild())
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var xTokens = await RetrieveTokensAsXTokenResponse ();
|
var xTokens = await RetrieveTokensAsXTokenResponse();
|
||||||
var result = new XUserClaimsInfoDto (
|
var result = new XUserClaimsInfoDto(
|
||||||
xTokens.AccessToken,
|
xTokens.AccessToken,
|
||||||
xTokens.RefreshToken,
|
xTokens.RefreshToken,
|
||||||
xTokens.ExpiresAt,
|
xTokens.ExpiresAt,
|
||||||
@@ -191,16 +234,19 @@ namespace xIdentityService.Controllers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public async Task<XUserClaimsInfoDto> ValidateAndGetUserInfo () {
|
public async Task<XUserClaimsInfoDto> ValidateAndGetUserInfo()
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (!User.Identity.IsAuthenticated) {
|
if (!User.Identity.IsAuthenticated)
|
||||||
XException.NotAuthorized.Throw ();
|
{
|
||||||
|
XException.NotAuthorized.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await GetUserInfo ();
|
var result = await GetUserInfo();
|
||||||
if (result.IsNull ()) {
|
if (result.IsNull())
|
||||||
XException.NotAuthorized.Throw ();
|
{
|
||||||
|
XException.NotAuthorized.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ namespace xIdentityService.Interfaces
|
|||||||
//
|
//
|
||||||
#region Open Actions ...
|
#region Open Actions ...
|
||||||
//
|
//
|
||||||
Task<XDeviceDto> GetDevice();
|
XDeviceDto GetDevice();
|
||||||
|
|
||||||
//
|
//
|
||||||
Task<XOpenActionInnerDto> OpenGet(
|
Task<XOpenActionInnerDto> OpenGet(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace xIdentityService.Providers
|
|||||||
/// Prepare API Based Device to Open Actions ...
|
/// Prepare API Based Device to Open Actions ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XDeviceDto> GetDevice()
|
public XDeviceDto GetDevice()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var os = "XSaherElmOS";
|
var os = "XSaherElmOS";
|
||||||
|
|||||||
@@ -23,11 +23,13 @@
|
|||||||
|
|
||||||
<!-- Local Modules -->
|
<!-- Local Modules -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- <PackageReference Include="xDashboard.xHttpService" Version="1.0.0" />
|
<PackageReference Include="xDashboard.xHttpService" Version="1.0.0" />
|
||||||
<PackageReference Include="xDashboard.xDataService" Version="1.0.0" /> -->
|
<!-- <PackageReference Include="xDashboard.xDataService" Version="1.0.0" /> -->
|
||||||
|
|
||||||
|
<ProjectReference Include="../xDataService/xDataService.csproj" />
|
||||||
|
<!--
|
||||||
<ProjectReference Include="../xHttpService/xHttpService.csproj" />
|
<ProjectReference Include="../xHttpService/xHttpService.csproj" />
|
||||||
<ProjectReference Include="../xDataService/xDataService.csproj" />
|
-->
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Dependencies -->
|
<!-- Dependencies -->
|
||||||
|
|||||||
Reference in New Issue
Block a user