TokenKey Generation (#235)

* Fixed #223. Now we generate a 128 byte JWT token key (recommendation) for user on first run.
This commit is contained in:
Joseph Milazzo 2021-05-31 10:14:39 -05:00 committed by GitHub
parent d7d7f9b529
commit 0a39a17407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,11 +35,13 @@ namespace API
public static async Task Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
// Before anything, check if JWT has been generated properly or if user still has default
if (!Configuration.CheckIfJwtTokenSet(GetAppSettingFilename()) && Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != Environments.Development)
{
Console.WriteLine("Generating JWT TokenKey for encrypting user sessions...");
var rBytes = new byte[24];
var rBytes = new byte[128];
using (var crypto = new RNGCryptoServiceProvider()) crypto.GetBytes(rBytes);
var base64 = Convert.ToBase64String(rBytes).Replace("/", "");
Configuration.UpdateJwtToken(GetAppSettingFilename(), base64);