oauth fixes to be able to use vault for env vars

This commit is contained in:
Dominic Villemure
2024-06-16 11:00:40 -04:00
parent 3902511e68
commit 568a5c99ca
5 changed files with 20 additions and 27 deletions

View File

@@ -221,9 +221,9 @@ public class IdentityService(
var user = await GetUserByUserNameAsync(userName);
var token = JwtTokenHelper.GenerateJwtToken(
issuer: configuration["Jwt:Issuer"] ?? "",
audience: configuration["Jwt:Audience"] ?? "",
key: configuration["Jwt:Key"] ?? "",
issuer: configuration["Jwt-Issuer"] ?? "",
audience: configuration["Jwt-Audience"] ?? "",
key: configuration["Jwt-Key"] ?? "",
userId: user?.Id ?? "");
return token;

View File

@@ -58,11 +58,11 @@ public class GoogleController(IIdentityService identityService, IHttpClientFacto
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
var issuer = configuration["Jwt:Issuer"] ??
var issuer = configuration["Jwt-Issuer"] ??
throw new ArgumentNullException("The Jwt issuer is missing.");
var audience = configuration["Jwt:Audience"] ??
var audience = configuration["Jwt-Audience"] ??
throw new ArgumentNullException("The Jwt audience is missing.");
var key = configuration["Jwt:Key"] ??
var key = configuration["Jwt-Key"] ??
throw new ArgumentNullException("The Jwt key is missing.");
var jwtToken = JwtTokenHelper.GenerateJwtToken(issuer, audience, key, user.Id);

View File

@@ -89,26 +89,26 @@ public static class DependencyInjection
jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = configuration["Jwt:Issuer"],
ValidIssuer = configuration["Jwt-Issuer"],
ValidateAudience = true,
ValidAudience = configuration["Jwt:Audience"],
ValidAudience = configuration["Jwt-Audience"],
ValidateLifetime = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"] ??
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt-Key"] ??
throw new ArgumentNullException("The Jwt Key is missing.")))
};
})
.AddGoogle(GoogleDefaults.AuthenticationScheme, options =>
{
options.ClientId = configuration["Google:ClientId"] ??
options.ClientId = configuration["Google-ClientId"] ??
throw new ArgumentNullException("The Google ClientId is missing.");;
options.ClientSecret = configuration["Google:ClientSecret"] ??
options.ClientSecret = configuration["Google-ClientSecret"] ??
throw new ArgumentNullException("The Google ClientSecret is missing.");;
})
.AddFacebook(FacebookDefaults.AuthenticationScheme, options =>
{
options.ClientId = configuration["Facebook:ClientId"] ??
options.ClientId = configuration["Facebook-ClientId"] ??
throw new ArgumentNullException("The Facebook ClientId is missing.");
options.ClientSecret = configuration["Facebook:ClientSecret"] ??
options.ClientSecret = configuration["Facebook-ClientSecret"] ??
throw new ArgumentNullException("The Facebook ClientSecret is missing.");
});

View File

@@ -1,6 +1,5 @@
using Hutopy.Application.Users.Commands;
using Hutopy.Application.Users.Queries.GetMinimalUser;
using Hutopy.Infrastructure.Identity;
namespace Hutopy.Web.Endpoints;

View File

@@ -7,17 +7,11 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Google": {
"ClientId": "",
"ClientSecret": ""
},
"Facebook": {
"ClientId": "",
"ClientSecret": ""
},
"Jwt": {
"Issuer": "",
"Audience": "",
"Key": ""
}
"Google-ClientId": "",
"Google-ClientSecret": "",
"Facebook-ClientId": "",
"Facebook-ClientSecret": "",
"Jwt-Audience": "",
"Jwt-Issuer": "",
"Jwt-Key": "",
}