首页 > 解决方案 > 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 似乎已正确配置

标签: facebookasp.net-coreazure-web-app-service

解决方案


问题是我的应用程序使用“http”方案(而不是“https”)传递给 facebook redirect_url。解决方案:

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

推荐阅读