mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 22:17:22 +01:00
- reload configs on change
- remove grpc config service replace with http - add messaging to channel
This commit is contained in:
parent
3490c5c8d8
commit
aa03d400d4
38 changed files with 304 additions and 377 deletions
|
|
@ -1,5 +1,5 @@
|
|||
using MareSynchronosShared.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
|
|
@ -9,7 +9,7 @@ namespace MareSynchronosShared.Utils;
|
|||
|
||||
public class ServerTokenGenerator
|
||||
{
|
||||
private readonly IConfigurationService<MareConfigurationAuthBase> _configuration;
|
||||
private readonly IOptionsMonitor<MareConfigurationAuthBase> _configuration;
|
||||
private readonly ILogger<ServerTokenGenerator> _logger;
|
||||
|
||||
private Dictionary<string, string> _tokenDictionary { get; set; } = new(StringComparer.Ordinal);
|
||||
|
|
@ -17,7 +17,7 @@ public class ServerTokenGenerator
|
|||
{
|
||||
get
|
||||
{
|
||||
var currentJwt = _configuration.GetValue<string>(nameof(MareConfigurationAuthBase.Jwt));
|
||||
var currentJwt = _configuration.CurrentValue.Jwt;
|
||||
if (_tokenDictionary.TryGetValue(currentJwt, out var token))
|
||||
{
|
||||
return token;
|
||||
|
|
@ -27,7 +27,7 @@ public class ServerTokenGenerator
|
|||
}
|
||||
}
|
||||
|
||||
public ServerTokenGenerator(IConfigurationService<MareConfigurationAuthBase> configuration, ILogger<ServerTokenGenerator> logger)
|
||||
public ServerTokenGenerator(IOptionsMonitor<MareConfigurationAuthBase> configuration, ILogger<ServerTokenGenerator> logger)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
|
|
@ -35,14 +35,14 @@ public class ServerTokenGenerator
|
|||
|
||||
private string GenerateToken()
|
||||
{
|
||||
var signingKey = _configuration.GetValue<string>(nameof(MareConfigurationAuthBase.Jwt));
|
||||
var signingKey = _configuration.CurrentValue.Jwt;
|
||||
var authSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(signingKey));
|
||||
|
||||
var token = new SecurityTokenDescriptor()
|
||||
{
|
||||
Subject = new ClaimsIdentity(new List<Claim>()
|
||||
{
|
||||
new Claim(MareClaimTypes.Uid, _configuration.GetValue<string>(nameof(MareConfigurationBase.ShardName))),
|
||||
new Claim(MareClaimTypes.Uid, _configuration.CurrentValue.ShardName),
|
||||
new Claim(MareClaimTypes.Internal, "true"),
|
||||
}),
|
||||
SigningCredentials = new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256Signature),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue