From c9dd2cc062cfbf95be018dcca4e3c7a6aa35ba25 Mon Sep 17 00:00:00 2001 From: Pedro Rebelo Date: Mon, 4 Jun 2018 16:33:07 +0100 Subject: [PATCH] Add a Request Prefix to TwitchAuthenticationOptions so that we don't rely always on Request.Scheme or Request.Host. --- .../TwitchAuthenticationHandler.cs | 14 +++++++++----- .../TwitchAuthenticationOptions.cs | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Owin.Security.Providers.Twitch/TwitchAuthenticationHandler.cs b/src/Owin.Security.Providers.Twitch/TwitchAuthenticationHandler.cs index b74caa5..4fe5dc9 100644 --- a/src/Owin.Security.Providers.Twitch/TwitchAuthenticationHandler.cs +++ b/src/Owin.Security.Providers.Twitch/TwitchAuthenticationHandler.cs @@ -60,8 +60,7 @@ namespace Owin.Security.Providers.Twitch return new AuthenticationTicket(null, properties); } - var requestPrefix = Request.Scheme + "://" + Request.Host; - var redirectUri = requestPrefix + Request.PathBase + Options.CallbackPath; + var redirectUri = GetRequestPrefix() + Request.PathBase + Options.CallbackPath; // Build up the body for the token request var body = new List> @@ -146,9 +145,7 @@ namespace Owin.Security.Providers.Twitch if (challenge == null) return Task.FromResult(null); var baseUri = - Request.Scheme + - Uri.SchemeDelimiter + - Request.Host + + GetRequestPrefix() + Request.PathBase; var currentUri = @@ -237,5 +234,12 @@ namespace Owin.Security.Providers.Twitch return context.IsRequestCompleted; } + + private string GetRequestPrefix() + { + return String.IsNullOrEmpty(Options.RequestPrefix) + ? Options.RequestPrefix + : Request.Scheme + Uri.SchemeDelimiter + Request.Host; + } } } \ No newline at end of file diff --git a/src/Owin.Security.Providers.Twitch/TwitchAuthenticationOptions.cs b/src/Owin.Security.Providers.Twitch/TwitchAuthenticationOptions.cs index 881c83a..009512a 100644 --- a/src/Owin.Security.Providers.Twitch/TwitchAuthenticationOptions.cs +++ b/src/Owin.Security.Providers.Twitch/TwitchAuthenticationOptions.cs @@ -125,6 +125,11 @@ namespace Owin.Security.Providers.Twitch /// public bool ForceVerify { get; set; } + /// + /// Gets or sets the Request prefix + /// + public string RequestPrefix { get; set; } + /// /// Initializes a new ///