【问题标题】:URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings?URL 被阻止:此重定向失败,因为重定向 URI 未在应用程序的客户端 OAuth 设置中列入白名单?
【发布时间】:2017-09-09 02:36:43
【问题描述】:

我点击链接 https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-how-to-configure-facebook-authentication 设置 Facebook 登录。

在https://developers.facebook.com/apps 中,“有效的 OAuth 重定向 URI”具有以下 URI

https://myapp.azurewebsites.net/.auth/login/facebook/callback 

但是还是报错?

URL 被阻止:此重定向失败,因为重定向 URI 未在应用的客户端 OAuth 设置中列入白名单。确保客户端和 Web OAuth 登录已打开,并将您的所有应用程序域添加为有效的 OAuth 重定向 URI。


更新: 添加了https://myapp.azurewebsites.net/signin-facebook 和https://myapp.azurewebsites.net/.auth/login/facebook/callback。现在网站出现了错误

A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or 'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider' was not present on the provided ClaimsIdentity. To enable anti-forgery token support with claims-based authentication, please verify that the configured claims provider is providing both of these claims on the ClaimsIdentity instances it generates. If the configured claims provider instead uses a different claim type as a unique identifier, it can be configured by setting the static property AntiForgeryConfig.UniqueClaimTypeIdentifier.。

在@Html.AntiForgeryToken()的线上d:\home\site\wwwroot\Views\Account\_ExternalLoginsListPartial.cshtm


更新: 在 global.asax 中添加了 followign 行,上面的错误就消失了。

AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;

但是,它只显示以下消息框,其 url 为 https://myapp.azurewebsites.net/.auth/login/done#_=_。

You have successfully signed in
-> RETURN TO THE WEBSITE

单击链接将返回登录屏幕。 https://myapp.azurewebsites.net/(不需要授权)而不是https://myapp.azurewebsites.net/event。输入https://myapp.azurewebsites.net/event 将再次显示登录页面。 (重定向到https://myapp.azurewebsites.net/Account/Login?ReturnUrl=%2Fevent)

【问题讨论】:

    标签: facebook azure azure-web-app-service facebook-apps


    【解决方案1】:

    作为官方tutorial,关于 Azure 应用服务中的身份验证和授权:

    应用服务身份验证/授权是一项功能,它为您的应用程序提供一种让用户登录的方式,以便您不必更改应用程序后端上的代码。它提供了一种简单的方法来保护您的应用程序并处理每个用户的数据。

    您可以浏览https://myapp.azurewebsites.net/.auth/login/facebook 进行登录。

    URL 被阻止:此重定向失败,因为重定向 URI 未在应用的客户端 OAuth 设置中列入白名单。确保客户端和 Web OAuth 登录已打开,并将您的所有应用程序域添加为有效的 OAuth 重定向 URI。

    您可以利用fiddler捕获网络包来检查您的facebook登录处理如下:

    注意:确保上述redirect_uri 已添加到有效的OAuth 重定向URI。 HTTP 或 HTTPS 可能是一个原因。

    另外,如果您使用中间件UseFacebookAuthentication 来验证使用Facebook 的用户,我假设您需要将http(s)://myapp.azurewebsites.net/signin-facebook 添加到有效的OAuth 重定向URI 或者您可以尝试使用以下代码:

    app.UseFacebookAuthentication(new FacebookAuthenticationOptions()
    {
        AppId = "{your-app-id}",
        AppSecret = "{your-app-secret}",
        CallbackPath = new PathString("/.auth/login/facebook/callback")
    });
    

    更新:

    我关注了tutorial 关于在 ASP.NET MVC5 中使用 OWIN 处理 Facebook 身份验证,我发现我无法检索记录的 facebook 用户信息并且returnUrl 不起作用。经过一番试验,我发现 Facebook 将图 API 从 v2.2 强制升级到 v2.3 如下:

    Facebook 图形 API,Changes from v2.2 to v2.3:

    [Oauth 访问令牌] 格式 - 当您为 access_token 交换代码时返回的 https://www.facebook.com/v2.3/oauth/access_token 的响应格式现在返回有效的 JSON,而不是 URL 编码。此响应的新格式为 {"access_token": {TOKEN}, "token_type":{TYPE}, "expires_in":{TIME}}。我们使此更新符合 RFC 6749 的第 5.1 节。

    你需要升级Microsoft.Owin.Security.Facebook到3.1.0,或者你需要实现这个issue中提到的BackchannelHttpHandler。

    【讨论】:

    • 我尝试使用 fiddler,但我的网络包似乎有所不同。它发布POST https://myapp.azurewebsites.net/Account/ExternalLogin?ReturnUrl=%2Fevent HTTP/1.1,然后隧道到CONNECT 2-edge-chat.facebook.com:443 HTTP/1.0,然后是GET https://2-edge-chat.facebook.com/pull?channel=p_100000343225510&seq=0&partition=-2&clientid=.....?
    • 又一次收到GET https://www.facebook.com/dialog/oauth?response_type=code&client_id=365322087148601&redirect_uri=https%3A%2F%2Fmyapp.azurewebsites.net%2Fsignin-facebook&scope=&state=3hmmvp23P8PQvmH78BtKA....。
    • 在“有效的 OAuth 重定向 URI”中清除并添加了 https://myapp.azurewebsites.net/signin-facebook。错误消失了。但是,它不会重定向到 /event 页面。
    • 然后我添加了代码CallbackPath = new PathString("/.auth/login/facebook/callback") (new FacebookAuthenticationOptions())。现在URL Blocked的错误又出现了。
    • 如您所述,您使用的是App Service Authentication/Authorization,此时,您需要将https://myapp.azurewebsites.net/.auth/login/facebook/callback 添加到“有效的OAuth 重定向URI”中,并且您不必添加任何中间件(例如@ 987654348@) 用于验证用户在您的后端登录。如果您使用app.UseFacebookAuthentication 通过您的网络应用程序本身处理facebook 身份验证,您需要将FacebookAuthenticationOptions 的默认CallbackPath (https://myapp.azurewebsites.net/signin-facebook) 添加到“有效的OAuth 重定向URI”。
    猜你喜欢
    • 2018-09-03
    • 1970-01-01
    • 2020-03-27
    • 2019-05-19
    • 2018-09-06
    • 2018-01-03
    相关资源
    最近更新 更多