Эх сурвалжийг харах

Consolidation of auth configuration

Lukas Angerer 3 жил өмнө
parent
commit
d1ef7d7386

+ 3 - 1
src/RunnersMeet.Server/AuthOptions.cs → src/RunnersMeet.Server/AuthSettings.cs

@@ -1,8 +1,10 @@
 // ReSharper disable CollectionNeverUpdated.Global
 namespace RunnersMeet.Server;
 
-public class AuthOptions
+public class AuthSettings
 {
+	public const string SectionName = "Auth";
+
 	public string Authority { get; set; } = String.Empty;
 	public string Audience { get; set; } = String.Empty;
 	public IDictionary<string, string[]> PolicyClaims { get; set; } = new Dictionary<string, string[]>();

+ 2 - 2
src/RunnersMeet.Server/AuthenticationModule.cs

@@ -7,8 +7,8 @@ public class AuthenticationModule : IAppConfigurationModule
 {
 	public void ConfigureServices(IServiceCollection services, IConfigurationRoot config)
 	{
-		var authOptions = new AuthOptions();
-		config.GetSection("Auth").Bind(authOptions);
+		// GetRequiredSection throws an exception if the section is missing, so authOptions always has a value
+		var authOptions = config.GetRequiredSection(AuthSettings.SectionName).Get<AuthSettings>()!;
 		services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
 			.AddJwtBearer(options =>
 			{