diff options
| author | Sanskar Pandey <sanskarpandey0@gmail.com> | 2022-10-07 04:05:06 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-07 04:05:06 +0530 |
| commit | 9fc05648a75b1c8022e3f034ff2abca47cdeaaf2 (patch) | |
| tree | e684ac785f9458fae25c219f44eb03031984d9f4 /src/slskd/Program.cs | |
| parent | 94d2536da26287e696662c82295c2fdc832ec856 (diff) | |
| parent | fb6350e107bd5f850a13c8c2065e341241967ab2 (diff) | |
| download | slskd-9fc05648a75b1c8022e3f034ff2abca47cdeaaf2.tar.gz | |
Merge branch 'master' into mutex-implementation
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 => { |
