gpt4 book ai didi

asp.net-mvc - Facebook 登录建议需要 HTTPS - 如何在 ASP.NET MVC 中为 Facebook 登录配置 HTTP 重定向 URL?

转载 作者:行者123 更新时间:2023-12-03 18:28:58 26 4
gpt4 key购买 nike

Facebook 建议我使用 HTTPS 重定向 URL,而不是 HTTP。我一直试图找到一种方法来配置它以生成 HTTPS URL,目前它正在生成一个 HTTP URL。

https://www.facebook.com/v2.8/dialog/oauth?response_type=code&client_id=255162614498922&redirect_uri=http://example.com/signin-facebook&scope=&state=-x4AVtFysadfadsfsadROH6E1QJ82gv4e4j48s32K5xbmqlF-JFbE5Y2Tx_MAdSquCP6CjZjic8Ye6gwasdfdfask3PXWkyxS42Ajpks9IuumDOl6CUJsadfafsasfdasdfbfpEFUDyxJUR3fARlWc83Lysadffdsdaffsdafasdsdafx_ziTnttz



目前正在生成: http://example.com/signin-facebookredirect_uri ,但我想要一个 HTTPS URL 来将用户重定向到。

有没有办法将其配置为生成 HTTPS URL?

这与软件包 Microsoft.Owin.Security 和 Microsoft.Owin.Security.Facebook 相关。

目前我的 OwinStart 看起来像这样:
public class OwinStart
{
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Welcome")
});

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

// Configure Facebook authentication
app.UseFacebookAuthentication(new FacebookAuthenticationOptions
{
AppId = ConfigurationManager.AppSettings["FacebookAppId"],
AppSecret = ConfigurationManager.AppSettings["FacebookAppSecret"]
});
}
}

此外,似乎没有在 FacebookAuthenticationOptions 中强制使用 HTTP 的方法。类或来自 Challenge()促使重定向到 Facebook 的方法:
internal class ChallengeResult : HttpUnauthorizedResult
{
// TODO: Specify an XsrfKey?
private const string XsrfKey = "SomethingHere";

public ChallengeResult(string provider, string redirectUri)
: this(provider, redirectUri, null)
{
}

public ChallengeResult(string provider, string redirectUri, string userId)
{
this.LoginProvider = provider;
this.RedirectUri = redirectUri;
this.UserId = userId;
}

public string LoginProvider { get; set; }
public string RedirectUri { get; set; }
public string UserId { get; set; }

public override void ExecuteResult(ControllerContext context)
{
var properties = new AuthenticationProperties { RedirectUri = this.RedirectUri };

if (this.UserId != null)
{
properties.Dictionary[XsrfKey] = this.UserId;
}

context.HttpContext.GetOwinContext().Authentication.Challenge(properties, this.LoginProvider);
}
}

最佳答案

感谢 Microsoft 的 Chris Ross 的帮助,我能够通过 raising the issue on Github 得到这个问题的答案。 .

看来Microsoft.Owin.Security Nuget 包生成 request_uri它根据当前的请求上下文指示 Facebook 使用。

就我而言,我通过 HTTP(不是 HTTPS)运行我的所有服务器,负载平衡器正在为我处理所有 HTTPS 内容。 IE。负载平衡器正在切断 SSL 连接。

确保包生成HTTPS的方法是在基于x-forwarded-proto的OwinStart配置方法中使用中间件。从负载均衡器转发的 header ,如下所示:

app.Use((context, next) =>
{
if (context.Request.Headers["x-forwarded-proto"] == "https")
{
context.Request.Scheme = "https";
}
return next();
});
// Use Cookies
// Use Facebook

所以我的 OwinStart 现在看起来像这样:
public class OwinStart
{
public void Configuration(IAppBuilder app)
{
app.Use((context, next) =>
{
if (context.Request.Headers["x-forwarded-proto"] == "https")
{
context.Request.Scheme = "https";
}
return next();
});

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Welcome")
});

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

// Configure Facebook authentication
app.UseFacebookAuthentication(new FacebookAuthenticationOptions
{
AppId = ConfigurationManager.AppSettings["FacebookAppId"],
AppSecret = ConfigurationManager.AppSettings["FacebookAppSecret"]
});
}
}

关于asp.net-mvc - Facebook 登录建议需要 HTTPS - 如何在 ASP.NET MVC 中为 Facebook 登录配置 HTTP 重定向 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48776900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com