refactor(DigitalData.Auth.Client): DigitalData.Core.Security wurde auf 1.1.0 aktualisiert.
This commit is contained in:
@@ -10,6 +10,8 @@ using DigitalData.Auth.API.Dto;
|
||||
using DigitalData.Auth.API.Services.Contracts;
|
||||
using DigitalData.Auth.API.Entities;
|
||||
using DigitalData.Core.DTO;
|
||||
using DigitalData.Core.Abstractions.Security.Services;
|
||||
using DigitalData.Core.Abstractions.Security.Extensions;
|
||||
|
||||
namespace DigitalData.Auth.API.Controllers
|
||||
{
|
||||
@@ -23,7 +25,7 @@ namespace DigitalData.Auth.API.Controllers
|
||||
|
||||
private readonly AuthApiParams _apiParams;
|
||||
|
||||
private readonly ICryptoFactory _cryptoFactory;
|
||||
private readonly IAsymmetricKeyPool _keyPool;
|
||||
|
||||
private readonly ILogger<AuthController> _logger;
|
||||
|
||||
@@ -33,11 +35,11 @@ namespace DigitalData.Auth.API.Controllers
|
||||
|
||||
private readonly IConsumerService _consumerService;
|
||||
|
||||
public AuthController(IJwtSignatureHandler<UserReadDto> userSignatureHandler, IOptions<AuthApiParams> cookieParamsOptions, ICryptoFactory cryptoFactory, ILogger<AuthController> logger, IUserService userService, IDirectorySearchService dirSearchService, IConsumerService consumerService, IJwtSignatureHandler<Consumer> apiSignatureHandler)
|
||||
public AuthController(IJwtSignatureHandler<UserReadDto> userSignatureHandler, IOptions<AuthApiParams> cookieParamsOptions, IAsymmetricKeyPool keyPool, ILogger<AuthController> logger, IUserService userService, IDirectorySearchService dirSearchService, IConsumerService consumerService, IJwtSignatureHandler<Consumer> apiSignatureHandler)
|
||||
{
|
||||
_apiParams = cookieParamsOptions.Value;
|
||||
_userSignatureHandler = userSignatureHandler;
|
||||
_cryptoFactory = cryptoFactory;
|
||||
_keyPool = keyPool;
|
||||
_logger = logger;
|
||||
_userService = userService;
|
||||
_dirSearchService = dirSearchService;
|
||||
@@ -82,7 +84,7 @@ namespace DigitalData.Auth.API.Controllers
|
||||
if (consumer is null)
|
||||
return Unauthorized();
|
||||
|
||||
if (!_cryptoFactory.TokenDescriptors.TryGet(_apiParams.Issuer, consumer.Audience, out var descriptor))
|
||||
if (!_keyPool.TokenDescriptors.TryGet(_apiParams.Issuer, consumer.Audience, out var descriptor))
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
|
||||
var token = _userSignatureHandler.WriteToken(uRes!.Data, descriptor);
|
||||
@@ -104,7 +106,7 @@ namespace DigitalData.Auth.API.Controllers
|
||||
if (consumer is null || consumer.Password != login.Password)
|
||||
return Unauthorized();
|
||||
|
||||
if (!_cryptoFactory.TokenDescriptors.TryGet(_apiParams.Issuer, _apiParams.LocalConsumer.Audience, out var descriptor))
|
||||
if (!_keyPool.TokenDescriptors.TryGet(_apiParams.Issuer, _apiParams.LocalConsumer.Audience, out var descriptor))
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
|
||||
var token = _consumerSignatureHandler.WriteToken(consumer, descriptor);
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="3.3.0" />
|
||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="3.4.0" />
|
||||
<PackageReference Include="DigitalData.Core.Abstractions.Security" Version="1.0.0" />
|
||||
<PackageReference Include="DigitalData.Core.Application" Version="3.2.0" />
|
||||
<PackageReference Include="DigitalData.Core.Security" Version="1.0.0" />
|
||||
<PackageReference Include="DigitalData.Core.Security" Version="1.2.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.3.1" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using DigitalData.Auth.Abstractions;
|
||||
using DigitalData.Core.Abstractions.Security;
|
||||
using DigitalData.Core.Abstractions.Security.Extensions;
|
||||
using DigitalData.Core.Abstractions.Security.Services;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
@@ -7,7 +8,7 @@ namespace DigitalData.Auth.API.Hubs;
|
||||
|
||||
public class AuthHub : Hub<IAuthListenHandler>, IAuthSenderHandler
|
||||
{
|
||||
private readonly ICryptoFactory _cFactory;
|
||||
private readonly IAsymmetricKeyPool _keyPool;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
@@ -15,16 +16,16 @@ public class AuthHub : Hub<IAuthListenHandler>, IAuthSenderHandler
|
||||
|
||||
private readonly static string CacheId = Guid.NewGuid().ToString();
|
||||
|
||||
public AuthHub(ICryptoFactory cryptoFactory, ILogger<AuthHub> logger, IMemoryCache cache)
|
||||
public AuthHub(IAsymmetricKeyPool cryptoFactory, ILogger<AuthHub> logger, IMemoryCache cache)
|
||||
{
|
||||
_cFactory = cryptoFactory;
|
||||
_keyPool = cryptoFactory;
|
||||
_logger = logger;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
public async Task GetPublicKeyAsync(string issuer, string audience)
|
||||
{
|
||||
if(_cFactory.TokenDescriptors.TryGet(issuer, audience, out var tDesc))
|
||||
if(_keyPool.TokenDescriptors.TryGet(issuer, audience, out var tDesc))
|
||||
{
|
||||
await Clients.Caller.ReceivePublicKeyAsync(issuer, audience, tDesc.PublicKey.Content);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ using DigitalData.Auth.API.Config;
|
||||
using DigitalData.Auth.API.Entities;
|
||||
using DigitalData.Auth.API.Hubs;
|
||||
using DigitalData.Auth.API.Services;
|
||||
using DigitalData.Core.Abstractions.Security;
|
||||
using DigitalData.Core.Abstractions.Security.Extensions;
|
||||
using DigitalData.Core.Abstractions.Security.Services;
|
||||
using DigitalData.Core.Application;
|
||||
using DigitalData.Core.Security;
|
||||
using DigitalData.Core.Security.Extensions;
|
||||
using DigitalData.UserManager.Application;
|
||||
using DigitalData.UserManager.Application.DTOs.User;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
@@ -30,7 +31,7 @@ try
|
||||
// Add services to the container.
|
||||
builder.Services.Configure<AuthApiParams>(config);
|
||||
builder.Services.AddAuthService(config);
|
||||
builder.Services.AddCryptoFactory(config.GetSection("CryptParams"));
|
||||
builder.Services.AddRSAPool(config.GetSection("CryptParams"));
|
||||
builder.Services.AddJwtSignatureHandler<Consumer>(api => new Dictionary<string, object>
|
||||
{
|
||||
{ JwtRegisteredClaimNames.Sub, api.Id },
|
||||
@@ -126,7 +127,7 @@ try
|
||||
|
||||
issuerSigningKeyInitiator = new Lazy<SecurityKey>(() =>
|
||||
{
|
||||
var factory = app.Services.GetRequiredService<ICryptoFactory>();
|
||||
var factory = app.Services.GetRequiredService<IAsymmetricKeyPool>();
|
||||
var desc = factory.TokenDescriptors.Get(apiParams.Issuer, apiParams.LocalConsumer.Audience);
|
||||
return desc.Validator.SecurityKey;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user