From ba08bffec3c97c40c161fd3cfb1c3c8f03f2a416 Mon Sep 17 00:00:00 2001 From: Hoku Kim Date: Fri, 13 Oct 2017 06:32:06 -0700 Subject: [PATCH] Added LinkedInAuthenticationOptions.Proxy host for web applications running behind a proxy. This allows the middleware to authenticate for the proxy request host instead of the application request host. (#213) --- .../LinkedInAuthenticationHandler.cs | 14 ++++++++++++-- .../LinkedInAuthenticationOptions.cs | 10 ++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Owin.Security.Providers.LinkedIn/LinkedInAuthenticationHandler.cs b/src/Owin.Security.Providers.LinkedIn/LinkedInAuthenticationHandler.cs index 2229472..d13d601 100644 --- a/src/Owin.Security.Providers.LinkedIn/LinkedInAuthenticationHandler.cs +++ b/src/Owin.Security.Providers.LinkedIn/LinkedInAuthenticationHandler.cs @@ -61,7 +61,7 @@ namespace Owin.Security.Providers.LinkedIn return new AuthenticationTicket(null, properties); } - var requestPrefix = Request.Scheme + "://" + Request.Host; + var requestPrefix = Request.Scheme + "://" + this.GetHostName(); var redirectUri = requestPrefix + Request.PathBase + Options.CallbackPath; // Build up the body for the token request @@ -173,7 +173,7 @@ namespace Owin.Security.Providers.LinkedIn var baseUri = Request.Scheme + Uri.SchemeDelimiter + - Request.Host + + this.GetHostName() + Request.PathBase; var currentUri = @@ -271,5 +271,15 @@ namespace Owin.Security.Providers.LinkedIn return context.IsRequestCompleted; } + + /// + /// Gets proxy host name from if it is set. + /// If proxy host name is not set, gets application request host name. + /// + /// Host name. + private string GetHostName() + { + return string.IsNullOrWhiteSpace(Options.ProxyHost) ? Request.Host.ToString() : Options.ProxyHost; + } } } \ No newline at end of file diff --git a/src/Owin.Security.Providers.LinkedIn/LinkedInAuthenticationOptions.cs b/src/Owin.Security.Providers.LinkedIn/LinkedInAuthenticationOptions.cs index 02aa95c..77cbc1d 100644 --- a/src/Owin.Security.Providers.LinkedIn/LinkedInAuthenticationOptions.cs +++ b/src/Owin.Security.Providers.LinkedIn/LinkedInAuthenticationOptions.cs @@ -43,6 +43,16 @@ namespace Owin.Security.Providers.LinkedIn /// public PathString CallbackPath { get; set; } + /// + /// Gets or sets the middleware host name. + /// The middleware processes the on this host name instead of the application's request host. + /// If this is not set, the application's request host will be used. + /// + /// + /// Use this property when running behind a proxy. + /// + public string ProxyHost { get; set; } + /// /// Get or sets the text that the user can display on a sign in user interface. ///