Fix Key Generation

This commit is contained in:
hydrant
2019-09-22 16:53:38 +02:00
parent b9c0db505c
commit f99178bf25
3 changed files with 29 additions and 22 deletions

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using ReallifeGamemode.Database;
@@ -15,11 +16,13 @@ namespace ReallifeGamemode.DataService.Logic
{
public class JwtTokenGenerator : LogicBase
{
private ServerConfig config;
private readonly ILogger<JwtTokenGenerator> logger;
private readonly ServerConfig config;
public JwtTokenGenerator(IOptions<ServerConfig> config, DatabaseContext dbContext) : base(dbContext)
public JwtTokenGenerator(IOptions<ServerConfig> config, DatabaseContext dbContext, ILogger<JwtTokenGenerator> logger) : base(dbContext)
{
this.config = config.Value;
this.logger = logger;
}
public string GenerateUserToken(User user)
@@ -40,10 +43,9 @@ namespace ReallifeGamemode.DataService.Logic
new Claim(ClaimTypes.Name, user.Id.ToString()),
new Claim(ClaimTypes.Role, user.AdminLevel.ToString())
}),
Expires = DateTime.Now.AddDays(1),
IssuedAt = DateTime.Now,
Expires = DateTime.UtcNow.AddDays(1),
IssuedAt = DateTime.UtcNow,
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature),
Issuer = "LOGDATASERVICE"
};
var token = tokenHandler.WriteToken(tokenHandler.CreateToken(tokenDescriptor));
@@ -62,10 +64,9 @@ namespace ReallifeGamemode.DataService.Logic
new Claim(ClaimTypes.Name, 1.ToString()),
new Claim(ClaimTypes.Role, (AdminLevel.PROJEKTLEITUNG).ToString())
}),
Expires = DateTime.Now.AddDays(1),
IssuedAt = DateTime.Now,
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature),
Issuer = "LOGDATASERVICE"
Expires = DateTime.UtcNow.AddDays(1),
IssuedAt = DateTime.UtcNow,
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.WriteToken(tokenHandler.CreateToken(tokenDescriptor));