Ansprüche über ModelExtensipons konfigurieren
This commit is contained in:
parent
b3e7c1aa99
commit
140f172369
18
DigitalData.UserManager.API/Models/ModelExtensions.cs
Normal file
18
DigitalData.UserManager.API/Models/ModelExtensions.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using DigitalData.UserManager.Application.DTOs.User;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
|
namespace DigitalData.UserManager.API.Models;
|
||||||
|
|
||||||
|
public static class ModelExtensions
|
||||||
|
{
|
||||||
|
public static List<Claim> ToClaimList(this UserReadDto user) => new()
|
||||||
|
{
|
||||||
|
new (ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||||
|
new (ClaimTypes.Name, user.Username),
|
||||||
|
new (ClaimTypes.Surname, user.Name ?? ""),
|
||||||
|
new (ClaimTypes.GivenName, user.Prename ?? ""),
|
||||||
|
new (ClaimTypes.Email, user.Email ?? "")
|
||||||
|
};
|
||||||
|
|
||||||
|
public static Dictionary<string, object> ToClaimDictionary(this UserReadDto user) => user.ToClaimList().ToDictionary(claim => claim.Type, claim => (object)claim.Value);
|
||||||
|
}
|
||||||
@ -10,6 +10,9 @@ using DigitalData.UserManager.API.Controllers;
|
|||||||
using DigitalData.UserManager.Application.Services;
|
using DigitalData.UserManager.Application.Services;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using DigitalData.UserManager.Application.DTOs.User;
|
||||||
|
using DigitalData.UserManager.API.Models;
|
||||||
|
|
||||||
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
||||||
logger.Debug("init main");
|
logger.Debug("init main");
|
||||||
@ -84,6 +87,10 @@ try {
|
|||||||
|
|
||||||
builder.ConfigureBySection<DirectorySearchOptions>();
|
builder.ConfigureBySection<DirectorySearchOptions>();
|
||||||
builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions"));
|
builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions"));
|
||||||
|
builder.Services.AddJWTService<UserReadDto>(user => new SecurityTokenDescriptor()
|
||||||
|
{
|
||||||
|
Claims = user.ToClaimList().ToDictionary(claim => claim.Type, claim => claim.Value as object)
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.AddCookieBasedLocalizer();
|
builder.Services.AddCookieBasedLocalizer();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user