diff options
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 8f24d69a..5414fccf 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -602,6 +602,22 @@ namespace slskd if (!OptionsAtStartup.Web.Authentication.Disabled) { + services.AddAuthorization(options => + { + options.AddPolicy(AuthPolicy.JwtOnly, policy => + { + policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme); + policy.RequireAuthenticatedUser(); + }); + + options.AddPolicy(AuthPolicy.Any, policy => + { + policy.AuthenticationSchemes.Add(ApiKeyAuthentication.AuthenticationScheme); + policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme); + policy.RequireAuthenticatedUser(); + }); + }); + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { @@ -633,20 +649,33 @@ namespace slskd return Task.CompletedTask; }, }; + }) + .AddScheme<ApiKeyAuthenticationOptions, ApiKeyAuthenticationHandler>(ApiKeyAuthentication.AuthenticationScheme, options => + { + options.EnableSignalRSupport = true; + options.SignalRRoutePrefix = "/hub"; + options.Role = Role.Administrator; }); - - //services.AddAuthentication(ApiKeyAuthentication.AuthenticationScheme) - // .AddScheme<ApiKeyAuthenticationOptions, ApiKeyAuthenticationHandler>(ApiKeyAuthentication.AuthenticationScheme, options => - // { - // options.EnableSignalRSupport = true; - // options.SignalRRoutePrefix = "/hub"; - // options.Role = Role.Administrator; - // }); } else { Log.Warning("Authentication of web requests is DISABLED"); + services.AddAuthorization(options => + { + options.AddPolicy(AuthPolicy.Any, policy => + { + policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme); + policy.RequireAuthenticatedUser(); + }); + + options.AddPolicy(AuthPolicy.JwtOnly, policy => + { + policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme); + policy.RequireAuthenticatedUser(); + }); + }); + services.AddAuthentication(PassthroughAuthentication.AuthenticationScheme) .AddScheme<PassthroughAuthenticationOptions, PassthroughAuthenticationHandler>(PassthroughAuthentication.AuthenticationScheme, options => { |
