Add XPerson as Owner inside XApiKeyValidation Result ...
Add UserID in XPersonDto ... handle User Retrievers from Claims ... Handle User Converters ...
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using xModels.Dtos;
|
||||
using xCommons.Constants;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Dtos;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Models;
|
||||
using System.Security.Claims;
|
||||
using xIdentityModels.Constants;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityModels.Configurations;
|
||||
using xExceptions.Constants;
|
||||
|
||||
namespace xIdentityModels.Extensions
|
||||
{
|
||||
@@ -398,7 +401,7 @@ namespace xIdentityModels.Extensions
|
||||
{
|
||||
//
|
||||
// if Allowed IPs Empty means all Client IPs is Valid ...
|
||||
var result =
|
||||
var result =
|
||||
!source.HasChild();
|
||||
if (result)
|
||||
{
|
||||
@@ -420,7 +423,7 @@ namespace xIdentityModels.Extensions
|
||||
if (dest == "::1")
|
||||
{
|
||||
//
|
||||
result = source.Any(s =>
|
||||
result = source.Any(s =>
|
||||
s.ToNormalString() == "127.0.0.1" ||
|
||||
s.ToNormalString() == "localhost");
|
||||
}
|
||||
@@ -502,5 +505,115 @@ namespace xIdentityModels.Extensions
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract ApiKey Validated User ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XPersonDto ExtractApiKeyUser(
|
||||
this ClaimsPrincipal source
|
||||
)
|
||||
{
|
||||
//
|
||||
XPersonDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (!source.IsNull() &&
|
||||
source.Claims.HasChild())
|
||||
{
|
||||
source.Claims.ExtractApiKeyUser();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract ApiKey Validated User ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XPersonDto ExtractApiKeyUser(
|
||||
this IEnumerable<Claim> source
|
||||
)
|
||||
{
|
||||
//
|
||||
XPersonDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (source.HasChild())
|
||||
{
|
||||
//
|
||||
result = new XPersonDto
|
||||
{
|
||||
UserId = source.FirstOrDefault(c => c.Type == XCustomClaims.UserId)?.Value ?? "",
|
||||
Avatar = source.FirstOrDefault(c => c.Type == XCustomClaims.Picture)?.Value ?? "",
|
||||
Username = source.FirstOrDefault(c => c.Type == XCustomClaims.UserName)?.Value ?? "",
|
||||
Lastname = source.FirstOrDefault(c => c.Type == XCustomClaims.LastName)?.Value ?? "",
|
||||
Firstname = source.FirstOrDefault(c => c.Type == XCustomClaims.FirstName)?.Value ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract JWT Validated User ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XPersonDto ExtractAuthenticatedUser(
|
||||
this ClaimsPrincipal source
|
||||
)
|
||||
{
|
||||
//
|
||||
XPersonDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (!source.IsNull() &&
|
||||
source.Claims.HasChild())
|
||||
{
|
||||
source.Claims.ExtractAuthenticatedUser();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract JWT Validated User ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XPersonDto ExtractAuthenticatedUser(
|
||||
this IEnumerable<Claim> source
|
||||
)
|
||||
{
|
||||
//
|
||||
XPersonDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (source.HasChild())
|
||||
{
|
||||
//
|
||||
result = new XPersonDto
|
||||
{
|
||||
UserId = source.FirstOrDefault(c => c.Type == XCustomClaims.UserId)?.Value ?? "",
|
||||
Avatar = source.FirstOrDefault(c => c.Type == XCustomClaims.Picture)?.Value ?? "",
|
||||
Username = source.FirstOrDefault(c => c.Type == XCustomClaims.UserName)?.Value ?? "",
|
||||
Lastname = source.FirstOrDefault(c => c.Type == XCustomClaims.LastName)?.Value ?? "",
|
||||
Firstname = source.FirstOrDefault(c => c.Type == XCustomClaims.FirstName)?.Value ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user