Azure应用服务(Asp.net core)Facebook登录问题(redirect_uri_mismatch)

Mar*_*cin 0 facebook azure-web-app-service asp.net-core

我在我的 Asp.Net core 应用程序中配置了 Facebook Login(根据https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/facebook-logins?view=aspnetcore-2.2) - 有效就像 localost 上的魅力一样。

但是,当我在 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)
Run Code Online (Sandbox Code Playgroud)

在我的 facebook 应用程序设置/基本/AppDomains 和 Facebook 登录/设置/有效 OAuth 重定向 URI 中似乎已正确配置

Mar*_*cin 5

问题是我的应用程序正在通过“http”方案(而不是“https”)传递到 facebook redirect_url。解决方案:

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