facebook - Azure App Service (Asp.net core) Facebook 登录问题 (redirect_uri_mismatch)
问题描述
我在我的 Asp.Net 核心应用程序中配置了 Facebook 登录(根据https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/facebook-logins?view=aspnetcore-2.2) - 有效就像本地人的魅力一样。
但是当我在 Azure 上部署我的应用程序时,我收到了这个错误(在单击 facebook 按钮并从 facebook 重定向到 https://.azurewebsites.net/signin-facebook?code=xxx 后:
System.Exception: An error was encountered while handling the remote login. ---> System.Exception: OAuth token endpoint failure: Status: BadRequest;Headers: Vary: Accept-Encoding
WWW-Authenticate: OAuth "Facebook Platform" "redirect_uri_mismatch" "Can't Load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings."
facebook-api-version: v3.1
Strict-Transport-Security: max-age=15552000; preload
Pragma: no-cache
x-fb-rev: 1000986790
Access-Control-Allow-Origin: *
Cache-Control: no-store
x-fb-trace-id: H0puEQmIpA5
x-fb-request-id: AWNLNIxmFnAZBZf50w85dNg
X-FB-Debug: 8KfmNQQZ/alv5CCUaaeJlpEEjMyh+Wqz8jV/YRg/WfIGTMRlIqByhhsHgD065MsT3c/JIUyfSYGH6rRm7wYLKA==
Date: Fri, 26 Jul 2019 08:06:07 GMT
Transfer-Encoding: chunked
Connection: keep-alive
;Body: {"error":{"message":"Can't Load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.","type":"OAuthException","code":191,"fbtrace_id":"AWNLNIxmFnAZBZf50w85dNg"}}; --- End of inner exception stack trace --- at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync() at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
在我的 facebook 应用程序 Settings/Basic/AppDomains 和 Facebook login/Settings/Valid OAuth Redirect URIs 似乎已正确配置
解决方案
问题是我的应用程序使用“http”方案(而不是“https”)传递给 facebook redirect_url。解决方案:
app.Use((context, next) =>
{
if (context.Request.Headers["x-forwarded-proto"] == "https")
{
context.Request.Scheme = "https";
}
return next();
});
推荐阅读
- python - A pandas-y way to produce a dataframe from a list that is created using a for-loop
- qt - winId 与 qml 的等价物是什么?
- java - 为什么我没有在 intellij 的类旁边运行图标?
- azure-api-management - 如何使用 azure api 管理进行自定义访问令牌检查并丰富请求中的数据
- spring-cloud-function - 如何使用消息流测试 Spring Cloud Function
- r - 将功能应用于特定列,同时保留其他列
- java - SimpleDateFormat 显示不一致的结果
- angularjs - Angular 代码在 Visual Studio 中工作,但在 IIS 中不工作
- dictionary - AttributeError:“dict”对象没有属性“append”并且测试失败
- sql-server - SQL Server 数据工具安装在 5 小时后安装 80% 后卡住