AppHarbor's Reverse Proxy causing issues with SSL and app.UseOAuthBearerTokens ASP.NET MVC 5 AppHarbor's Reverse Proxy causing issues with SSL and app.UseOAuthBearerTokens ASP.NET MVC 5 nginx nginx

AppHarbor's Reverse Proxy causing issues with SSL and app.UseOAuthBearerTokens ASP.NET MVC 5


You could try and register some middleware that can modify requests based on the headers forwarded by nginx. You probably also want to set the remote IP address to the value of the X-Forwarded-For header.

Something like this should work (untested):

public class AppHarborMiddleware : OwinMiddleware{    public AppHarborMiddleware(OwinMiddleware next)        : base(next)    {    }    public override Task Invoke(IOwinContext context)    {        if (string.Equals(context.Request.Headers["X-Forwarded-Proto"], "https", StringComparison.InvariantCultureIgnoreCase))        {            context.Request.Scheme = "https";        }        var forwardedForHeader = context.Request.Headers["X-Forwarded-For"];        if (!string.IsNullOrEmpty(forwardedForHeader))        {            context.Request.RemoteIpAddress = forwardedForHeader;        }        return Next.Invoke(context);    }}

Make sure to add it before you configure the authentication middleware:

app.Use<AppHarborMiddleware>();app.UseOAuthBearerTokens(new OAuthAuthorizationServerOptions{    AllowInsecureHttp = false,});