aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Security/PassthroughAuthentication.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2020-12-30 21:16:50 -0600
committerJP Dillingham <jpdillingham@gmail.com>2020-12-30 21:16:50 -0600
commit8f1068ac3135bcccf09374bc787ef22049b43461 (patch)
tree5d80a254f5ee7b7c6b3956f6a7307591bc5a93e2 /src/slskd/Security/PassthroughAuthentication.cs
parentec4a85e4e8b64a0ae91c494e3c8ef520f0a8b8c3 (diff)
downloadslskd-8f1068ac3135bcccf09374bc787ef22049b43461.tar.gz
copy files from example
Diffstat (limited to 'src/slskd/Security/PassthroughAuthentication.cs')
-rw-r--r--src/slskd/Security/PassthroughAuthentication.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/slskd/Security/PassthroughAuthentication.cs b/src/slskd/Security/PassthroughAuthentication.cs
new file mode 100644
index 00000000..69b94df5
--- /dev/null
+++ b/src/slskd/Security/PassthroughAuthentication.cs
@@ -0,0 +1,40 @@
+namespace slskd.Security
+{
+ using Microsoft.AspNetCore.Authentication;
+ using Microsoft.Extensions.Logging;
+ using Microsoft.Extensions.Options;
+ using System.Security.Principal;
+ using System.Text.Encodings.Web;
+ using System.Threading.Tasks;
+
+ public class PassthroughAuthentication
+ {
+ public static string AuthenticationScheme { get; } = "Passthrough";
+ }
+
+ public class PassthroughAuthenticationHandler : AuthenticationHandler<PassthroughAuthenticationOptions>
+ {
+ public PassthroughAuthenticationHandler(IOptionsMonitor<PassthroughAuthenticationOptions> optionsMonitor, ILoggerFactory logger, UrlEncoder urlEncoder, ISystemClock systemClock)
+ : base(optionsMonitor, logger, urlEncoder, systemClock)
+ {
+ }
+
+ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
+ {
+ var identity = new GenericIdentity(Options.Username);
+ var principal = new GenericPrincipal(identity, new[] { "User" });
+ var ticket = new AuthenticationTicket(principal , new AuthenticationProperties(), PassthroughAuthentication.AuthenticationScheme);
+
+ return Task.FromResult(AuthenticateResult.Success(ticket));
+ }
+ }
+
+ public class PassthroughAuthenticationOptions : AuthenticationSchemeOptions
+ {
+ public PassthroughAuthenticationOptions()
+ {
+ }
+
+ public string Username { get; set; }
+ }
+}