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 user = await GetUserByUserNameAsync(userName);
var token = JwtTokenHelper.GenerateJwtToken( var token = JwtTokenHelper.GenerateJwtToken(
issuer: configuration["Jwt:Issuer"] ?? "", issuer: configuration["Jwt-Issuer"] ?? "",
audience: configuration["Jwt:Audience"] ?? "", audience: configuration["Jwt-Audience"] ?? "",
key: configuration["Jwt:Key"] ?? "", key: configuration["Jwt-Key"] ?? "",
userId: user?.Id ?? ""); userId: user?.Id ?? "");
return token; return token;

View File

@@ -58,11 +58,11 @@ public class GoogleController(IIdentityService identityService, IHttpClientFacto
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)); 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."); 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."); 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."); throw new ArgumentNullException("The Jwt key is missing.");
var jwtToken = JwtTokenHelper.GenerateJwtToken(issuer, audience, key, user.Id); var jwtToken = JwtTokenHelper.GenerateJwtToken(issuer, audience, key, user.Id);

View File

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

View File

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

View File

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