Skip to content

Commit d57750a

Browse files
key is saved in base64 in appsettings just to give an idead that it should be encrypted and the key can be placed in a secure centralized place
1 parent da7beb8 commit d57750a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

UserManagementApi/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
builder.Services.Configure<JwtOptions>(builder.Configuration.GetSection("Jwt"));
3131
var jwt = builder.Configuration.GetSection("Jwt").Get<JwtOptions>()!;
3232

33+
var keyBase64 = builder.Configuration["Jwt:KeyBase64"]!;
34+
var keyPlain = Encoding.UTF8.GetString(Convert.FromBase64String(keyBase64));
35+
3336
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
3437
.AddJwtBearer(opt =>
3538
{
@@ -40,7 +43,7 @@
4043
ValidateIssuerSigningKey = true,
4144
ValidIssuer = jwt.Issuer,
4245
ValidAudience = jwt.Audience,
43-
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwt.Key)),
46+
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(keyPlain)),
4447
ClockSkew = TimeSpan.Zero
4548
};
4649
});

UserManagementApi/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"Jwt": {
2828
"Issuer": "PermsApi",
2929
"Audience": "PermsApiAudience",
30-
"Key": "very_long_dev_key_change_in_prod_1234567890",
30+
"KeyBase64": "dmVyeV9sb25nX2Rldl9rZXlfY2hhbmdlX2luX3Byb2RfMTIzNDU2Nzg5MA==",
3131
"ExpiresMinutes": 60
3232
}
3333

0 commit comments

Comments
 (0)