Compare commits
4 Commits
a77c70f655
...
b4366e5bbb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4366e5bbb | ||
|
|
fab002a20c | ||
|
|
51492110a7 | ||
|
|
421f2657dd |
@ -1,4 +1,4 @@
|
|||||||
using DigitalData.Core.Abstractions.Security;
|
using DigitalData.Core.Abstractions.Security.Extensions;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace DigitalData.Auth.Client;
|
namespace DigitalData.Auth.Client;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using DigitalData.Core.Abstractions.Security;
|
using DigitalData.Core.Abstractions.Security.Common;
|
||||||
using DigitalData.Core.Security.RSAKey;
|
using DigitalData.Core.Abstractions.Security.Key;
|
||||||
|
using DigitalData.Core.Security.RSAKey.Base;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<PackageId>DigitalData.Auth.Client</PackageId>
|
<PackageId>DigitalData.Auth.Client</PackageId>
|
||||||
<Version>1.3.3</Version>
|
<Version>1.3.5</Version>
|
||||||
<Description>DigitalData.Auth.Client is a SignalR-based authentication client that enables applications to connect to a central authentication hub for real-time message exchange. It provides seamless connection management, automatic reconnection (RetryPolicy), and event-driven communication (ClientEvents). The package includes dependency injection support via DIExtensions, allowing easy integration into ASP.NET Core applications. With built-in retry policies and secure message handling, it ensures a reliable and scalable authentication client for real-time authentication workflows.</Description>
|
<Description>DigitalData.Auth.Client is a SignalR-based authentication client that enables applications to connect to a central authentication hub for real-time message exchange. It provides seamless connection management, automatic reconnection (RetryPolicy), and event-driven communication (ClientEvents). The package includes dependency injection support via DIExtensions, allowing easy integration into ASP.NET Core applications. With built-in retry policies and secure message handling, it ensures a reliable and scalable authentication client for real-time authentication workflows.</Description>
|
||||||
<Company>Digital Data GmbH</Company>
|
<Company>Digital Data GmbH</Company>
|
||||||
<Product>Digital Data GmbH</Product>
|
<Product>Digital Data GmbH</Product>
|
||||||
@ -14,8 +14,8 @@
|
|||||||
<PackageIcon>auth_icon.png</PackageIcon>
|
<PackageIcon>auth_icon.png</PackageIcon>
|
||||||
<RepositoryUrl>http://git.dd:3000/AppStd/DigitalData.Auth</RepositoryUrl>
|
<RepositoryUrl>http://git.dd:3000/AppStd/DigitalData.Auth</RepositoryUrl>
|
||||||
<PackageTags>Digital Data Auth Authorization Authentication</PackageTags>
|
<PackageTags>Digital Data Auth Authorization Authentication</PackageTags>
|
||||||
<AssemblyVersion>1.3.3</AssemblyVersion>
|
<AssemblyVersion>1.3.5</AssemblyVersion>
|
||||||
<FileVersion>1.3.3</FileVersion>
|
<FileVersion>1.3.5</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -26,9 +26,17 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="3.3.0" />
|
<PackageReference Include="DigitalData.Core.Abstractions.Security" Version="1.0.0" />
|
||||||
<PackageReference Include="DigitalData.Core.Security" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.Security" Version="1.2.3" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.1" />
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.20" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.14" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
using DigitalData.Auth.Abstractions;
|
using DigitalData.Auth.Abstractions;
|
||||||
using DigitalData.Auth.API.Hubs;
|
using DigitalData.Auth.API.Hubs;
|
||||||
using DigitalData.Auth.Client;
|
using DigitalData.Auth.Client;
|
||||||
using DigitalData.Core.Abstractions.Security;
|
using DigitalData.Core.Abstractions.Security.Extensions;
|
||||||
using DigitalData.Core.Security;
|
|
||||||
using DigitalData.Core.Security.Config;
|
using DigitalData.Core.Security.Config;
|
||||||
using DigitalData.Core.Security.RSAKey;
|
using DigitalData.Core.Security.Extensions;
|
||||||
|
using DigitalData.Core.Security.RSAKey.Auth;
|
||||||
|
using DigitalData.Core.Security.RSAKey.Crypto;
|
||||||
|
using DigitalData.Core.Security.Services;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
@ -46,7 +48,7 @@ public class AuthClientTests
|
|||||||
Issuer = "Foo",
|
Issuer = "Foo",
|
||||||
Audience = "Bar",
|
Audience = "Bar",
|
||||||
Lifetime = new TimeSpan(1, 0, 0),
|
Lifetime = new TimeSpan(1, 0, 0),
|
||||||
Content = Instance.RSAFactory.CreatePrivateKeyPem()
|
Content = RSAFactory.Static.CreatePrivateKeyPem()
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -56,7 +58,7 @@ public class AuthClientTests
|
|||||||
// Create builder and add SignalR service
|
// Create builder and add SignalR service
|
||||||
var builder = WebApplication.CreateBuilder();
|
var builder = WebApplication.CreateBuilder();
|
||||||
builder.Services.AddSignalR();
|
builder.Services.AddSignalR();
|
||||||
builder.Services.AddCryptoFactory(new CryptoFactoryParams()
|
builder.Services.AddRSAPool(new RSAParams()
|
||||||
{
|
{
|
||||||
PemDirectory = "/",
|
PemDirectory = "/",
|
||||||
Decryptors = [new RSADecryptor()],
|
Decryptors = [new RSADecryptor()],
|
||||||
@ -76,8 +78,8 @@ public class AuthClientTests
|
|||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CryptoFactoryParams GetCryptoFactoryParamsOf(WebApplication application) => application
|
private static RSAParams GetCryptoFactoryParamsOf(WebApplication application) => application
|
||||||
.Services.GetRequiredService<IOptions<CryptoFactoryParams>>().Value;
|
.Services.GetRequiredService<IOptions<RSAParams>>().Value;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||||
<PackageReference Include="DigitalData.Core.Security" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.Security" Version="1.2.2" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
<PackageReference Include="NUnit" Version="3.14.0" />
|
<PackageReference Include="NUnit" Version="3.14.0" />
|
||||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
|
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
|
||||||
|
|||||||
@ -10,6 +10,8 @@ using DigitalData.Auth.API.Dto;
|
|||||||
using DigitalData.Auth.API.Services.Contracts;
|
using DigitalData.Auth.API.Services.Contracts;
|
||||||
using DigitalData.Auth.API.Entities;
|
using DigitalData.Auth.API.Entities;
|
||||||
using DigitalData.Core.DTO;
|
using DigitalData.Core.DTO;
|
||||||
|
using DigitalData.Core.Abstractions.Security.Services;
|
||||||
|
using DigitalData.Core.Abstractions.Security.Extensions;
|
||||||
|
|
||||||
namespace DigitalData.Auth.API.Controllers
|
namespace DigitalData.Auth.API.Controllers
|
||||||
{
|
{
|
||||||
@ -23,7 +25,7 @@ namespace DigitalData.Auth.API.Controllers
|
|||||||
|
|
||||||
private readonly AuthApiParams _apiParams;
|
private readonly AuthApiParams _apiParams;
|
||||||
|
|
||||||
private readonly ICryptoFactory _cryptoFactory;
|
private readonly IAsymmetricKeyPool _keyPool;
|
||||||
|
|
||||||
private readonly ILogger<AuthController> _logger;
|
private readonly ILogger<AuthController> _logger;
|
||||||
|
|
||||||
@ -33,11 +35,11 @@ namespace DigitalData.Auth.API.Controllers
|
|||||||
|
|
||||||
private readonly IConsumerService _consumerService;
|
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;
|
_apiParams = cookieParamsOptions.Value;
|
||||||
_userSignatureHandler = userSignatureHandler;
|
_userSignatureHandler = userSignatureHandler;
|
||||||
_cryptoFactory = cryptoFactory;
|
_keyPool = keyPool;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
_dirSearchService = dirSearchService;
|
_dirSearchService = dirSearchService;
|
||||||
@ -82,7 +84,7 @@ namespace DigitalData.Auth.API.Controllers
|
|||||||
if (consumer is null)
|
if (consumer is null)
|
||||||
return Unauthorized();
|
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);
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
|
||||||
var token = _userSignatureHandler.WriteToken(uRes!.Data, descriptor);
|
var token = _userSignatureHandler.WriteToken(uRes!.Data, descriptor);
|
||||||
@ -104,7 +106,7 @@ namespace DigitalData.Auth.API.Controllers
|
|||||||
if (consumer is null || consumer.Password != login.Password)
|
if (consumer is null || consumer.Password != login.Password)
|
||||||
return Unauthorized();
|
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);
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
|
||||||
var token = _consumerSignatureHandler.WriteToken(consumer, descriptor);
|
var token = _consumerSignatureHandler.WriteToken(consumer, descriptor);
|
||||||
|
|||||||
@ -1,18 +1,19 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Version>1.1.0</Version>
|
<Version>1.1.2</Version>
|
||||||
<AssemblyVersion>1.1.0</AssemblyVersion>
|
<AssemblyVersion>1.1.2</AssemblyVersion>
|
||||||
<FileVersion>1.1.0</FileVersion>
|
<FileVersion>1.1.2</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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.Application" Version="3.2.0" />
|
||||||
<PackageReference Include="DigitalData.Core.Security" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.Security" Version="1.2.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.12" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.12" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
|
||||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.3.1" />
|
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.3.1" />
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using DigitalData.Auth.Abstractions;
|
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.AspNetCore.SignalR;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
|
||||||
@ -7,7 +8,7 @@ namespace DigitalData.Auth.API.Hubs;
|
|||||||
|
|
||||||
public class AuthHub : Hub<IAuthListenHandler>, IAuthSenderHandler
|
public class AuthHub : Hub<IAuthListenHandler>, IAuthSenderHandler
|
||||||
{
|
{
|
||||||
private readonly ICryptoFactory _cFactory;
|
private readonly IAsymmetricKeyPool _keyPool;
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
@ -15,16 +16,16 @@ public class AuthHub : Hub<IAuthListenHandler>, IAuthSenderHandler
|
|||||||
|
|
||||||
private readonly static string CacheId = Guid.NewGuid().ToString();
|
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;
|
_logger = logger;
|
||||||
_cache = cache;
|
_cache = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task GetPublicKeyAsync(string issuer, string audience)
|
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);
|
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.Entities;
|
||||||
using DigitalData.Auth.API.Hubs;
|
using DigitalData.Auth.API.Hubs;
|
||||||
using DigitalData.Auth.API.Services;
|
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.Application;
|
||||||
using DigitalData.Core.Security;
|
using DigitalData.Core.Security.Extensions;
|
||||||
using DigitalData.UserManager.Application;
|
using DigitalData.UserManager.Application;
|
||||||
using DigitalData.UserManager.Application.DTOs.User;
|
using DigitalData.UserManager.Application.DTOs.User;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
@ -30,7 +31,7 @@ try
|
|||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.Configure<AuthApiParams>(config);
|
builder.Services.Configure<AuthApiParams>(config);
|
||||||
builder.Services.AddAuthService(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>
|
builder.Services.AddJwtSignatureHandler<Consumer>(api => new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ JwtRegisteredClaimNames.Sub, api.Id },
|
{ JwtRegisteredClaimNames.Sub, api.Id },
|
||||||
@ -126,7 +127,7 @@ try
|
|||||||
|
|
||||||
issuerSigningKeyInitiator = new Lazy<SecurityKey>(() =>
|
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);
|
var desc = factory.TokenDescriptors.Get(apiParams.Issuer, apiParams.LocalConsumer.Audience);
|
||||||
return desc.Validator.SecurityKey;
|
return desc.Validator.SecurityKey;
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user