aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-05 18:30:31 -0500
committerJP Dillingham <jp@dillingham.me>2022-10-05 18:30:31 -0500
commitcd6874b3dd54c6b3e501439d308d591e4b2aada5 (patch)
treec2641f61004527822b98aec8b1cd33436f71a78d /src/slskd/Program.cs
parentfae0729152ff1db8c4fd25c0c7a667bb3b76962e (diff)
downloadslskd-cd6874b3dd54c6b3e501439d308d591e4b2aada5.tar.gz
add auth policies
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index c9417ed8..43d802b1 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -579,6 +579,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 =>
{
@@ -610,20 +626,27 @@ 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();
+ });
+ });
+
services.AddAuthentication(PassthroughAuthentication.AuthenticationScheme)
.AddScheme<PassthroughAuthenticationOptions, PassthroughAuthenticationHandler>(PassthroughAuthentication.AuthenticationScheme, options =>
{