2017-04-13 1850 views
0

我跟着链接https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-how-to-configure-facebook-authentication设置了Facebook登录。URL阻止:此重定向失败,因为重定向URI未在应用的客户端OAuth设置中列入白名单?

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-facebookhttps://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; 

但是,它只是显示下面的消息框与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

回答

2

正如这位官员tutorial有关身份验证和授权在Azure的应用服务:

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

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

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

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

enter image description here

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

此外,如果您使用中间件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关于处理Facebook身份验证通过在ASP.NET MVC5 OWIN,我发现我无法检索登录Facebook的用户inf o和returnUrl不起作用。一些试验后,我发现Facebook上做了图形API的升级力从V2.2到V2.3如下:

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

[OAuth访问令牌]格式 - https://www.facebook.com/v2.3/oauth/access_token的响应格式返回当您交换的代码时,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

+0

我试图使用提琴手和我的网络包似乎不同。它发布'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 = .....'? – ca9163d9

+0

另一次我得到'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 .... '。 – ca9163d9

+0

清除并在“有效的OAuth重定向URI”中添加了“https:// myapp.azurewebsites.net/signin-facebook”。错误消失了。但是,它不会重定向到'/ event'页面。 – ca9163d9