aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-06 08:41:00 -0500
committerGitHub <noreply@github.com>2022-10-06 08:41:00 -0500
commitfb6350e107bd5f850a13c8c2065e341241967ab2 (patch)
tree73e1aaa9e197df71f28accec82121581774a1aad /src/slskd/Program.cs
parentb879d7109ccde713b17258dc6d1e89624fdb6603 (diff)
parent55db59a4ef022befd503cee7247e5f4f5e403ef8 (diff)
downloadslskd-fb6350e107bd5f850a13c8c2065e341241967ab2.tar.gz
Merge pull request #681 from slskd/fix-auth
Add authorization policies
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index f01dcbe4..dc3054dc 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,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 =>
{