Sort Ordering Usings ...
Using ApiKey Validations and Claims Parsing from Extensions ...
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using IdentityModel;
|
||||
using System.Threading;
|
||||
using xCommons.Constants;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Models;
|
||||
@@ -9,7 +7,7 @@ using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using xIdentityModels.Constants;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityModels.Extensions;
|
||||
using xIdentityService.Constants;
|
||||
using xIdentityService.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
@@ -156,38 +154,9 @@ namespace xIdentityService.Attributes
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var device = identityService.GetDevice();
|
||||
var userInfo = await identityService.GetUserInfo(
|
||||
device: device,
|
||||
userSelectByParam: validationResponse.OwnerId
|
||||
);
|
||||
|
||||
//
|
||||
// Creating Claims ...
|
||||
var claims = new List<Claim> {
|
||||
//
|
||||
// Owner Identifier of API Key ...
|
||||
new(ClaimTypes.Name, validationResponse.OwnerId),
|
||||
new(JwtClaimTypes.Subject, validationResponse.OwnerId),
|
||||
//
|
||||
// Application Id ...
|
||||
new(XCustomClaims.ApplicationId, validationResponse.ApplicationId.ToString()),
|
||||
//
|
||||
// Authentication Type ...
|
||||
new(XCustomClaims.AuthType, apiKeyAuthentication),
|
||||
};
|
||||
|
||||
//
|
||||
// Add Scopes ...
|
||||
if (validationResponse.Scopes != null)
|
||||
{
|
||||
//
|
||||
foreach (var scope in validationResponse.Scopes)
|
||||
{
|
||||
claims.Add(new Claim(JwtClaimTypes.Scope, scope));
|
||||
}
|
||||
}
|
||||
var claims = validationResponse.ToXClaims();
|
||||
|
||||
//
|
||||
// Create Principal and Ticket ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using xModels.Dtos;
|
||||
using xCommons.Constants;
|
||||
using xCommons.Providers;
|
||||
using xCommons.Extensions;
|
||||
@@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using xIdentityModels.Constants;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityService.Constants;
|
||||
using xIdentityModels.Extensions;
|
||||
using xIdentityService.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
@@ -82,7 +84,7 @@ namespace xIdentityService.Controllers
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -106,7 +108,7 @@ namespace xIdentityService.Controllers
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -303,6 +305,66 @@ namespace xIdentityService.Controllers
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Authenticated ApiKey Person ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public XPersonDto GetApiKeyPerson()
|
||||
{
|
||||
//
|
||||
var result = User.ExtractApiKeyUser();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate and Get Authenticated ApiKey Person ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public XPersonDto ValidateAndGetApiKeyPerson()
|
||||
{
|
||||
//
|
||||
var result = User.ExtractApiKeyUser();
|
||||
if (result.IsNullOrDefault())
|
||||
{
|
||||
XException.NotAuthorized.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Authenticated JWT Person ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public XPersonDto GetAuthenticatedPerson()
|
||||
{
|
||||
//
|
||||
var result = User.ExtractAuthenticatedUser();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate and Get Authenticated JWT Person ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public XPersonDto ValidateAndGetAuthenticatedPerson()
|
||||
{
|
||||
//
|
||||
var result = User.ExtractAuthenticatedUser();
|
||||
if (result.IsNullOrDefault())
|
||||
{
|
||||
XException.NotAuthorized.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ namespace xIdentityService.Extensions
|
||||
//
|
||||
var result = new XPersonDto
|
||||
{
|
||||
UserId = source.UserId,
|
||||
Avatar = source.Avatar,
|
||||
Lastname = source.Lastname,
|
||||
Username = source.Username,
|
||||
|
||||
Reference in New Issue
Block a user