Sort Ordering Usings ...
Using ApiKey Validations and Claims Parsing from Extensions ...
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using IdentityModel;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using xCommons.Constants;
|
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xIdentityModels.Models;
|
using xIdentityModels.Models;
|
||||||
@@ -9,7 +7,7 @@ using System.Security.Claims;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using xIdentityModels.Constants;
|
using xIdentityModels.Constants;
|
||||||
using System.Collections.Generic;
|
using xIdentityModels.Extensions;
|
||||||
using xIdentityService.Constants;
|
using xIdentityService.Constants;
|
||||||
using xIdentityService.Interfaces;
|
using xIdentityService.Interfaces;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
@@ -156,38 +154,9 @@ namespace xIdentityService.Attributes
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
var device = identityService.GetDevice();
|
|
||||||
var userInfo = await identityService.GetUserInfo(
|
|
||||||
device: device,
|
|
||||||
userSelectByParam: validationResponse.OwnerId
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Creating Claims ...
|
// Creating Claims ...
|
||||||
var claims = new List<Claim> {
|
var claims = validationResponse.ToXClaims();
|
||||||
//
|
|
||||||
// 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create Principal and Ticket ...
|
// Create Principal and Ticket ...
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using xModels.Dtos;
|
||||||
using xCommons.Constants;
|
using xCommons.Constants;
|
||||||
using xCommons.Providers;
|
using xCommons.Providers;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
@@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using xIdentityModels.Constants;
|
using xIdentityModels.Constants;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using xIdentityService.Constants;
|
using xIdentityService.Constants;
|
||||||
|
using xIdentityModels.Extensions;
|
||||||
using xIdentityService.Interfaces;
|
using xIdentityService.Interfaces;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
@@ -82,7 +84,7 @@ namespace xIdentityService.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -106,7 +108,7 @@ namespace xIdentityService.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -303,6 +305,66 @@ namespace xIdentityService.Controllers
|
|||||||
//
|
//
|
||||||
return result;
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ namespace xIdentityService.Extensions
|
|||||||
//
|
//
|
||||||
var result = new XPersonDto
|
var result = new XPersonDto
|
||||||
{
|
{
|
||||||
|
UserId = source.UserId,
|
||||||
Avatar = source.Avatar,
|
Avatar = source.Avatar,
|
||||||
Lastname = source.Lastname,
|
Lastname = source.Lastname,
|
||||||
Username = source.Username,
|
Username = source.Username,
|
||||||
|
|||||||
Reference in New Issue
Block a user