[英]Facebook OAuth issue MVC4
令人煩惱的是,我已經嘗試解決這個問題很多小時了,每個答案都不是直接的解決方案:
{
"error": {
"message": "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request",
"type": "OAuthException",
"code": 100
}
}
我一直在撞牆! 我為此http://pastebin.com/G7ysgbdX使用了Facebook肥皂客戶端
這將使我們能夠(在用戶許可下)整合他們的時間表。 Facebook表示網址不匹配。 我該如何測試?
這在本地有效,但不能在服務器上使用完全相同的代碼,除了http://free-rsvp.com/而不是localhost:53111 /
這是下面的URL。 我看不到任何錯誤!
任何意見,將不勝感激。
provider_%3dFacebookPro%26_ SID _%3da80359b555c54b8f8d2f4f8e803f9125&client_secret = 212360b3ea6478fd0a0491e736b54256&代碼= AQCyTDStiB5gsQpKMx4uI1yFesVnLnWfE3u70VsB02-4HSyUCTbcf_3oHMo7QQI2as_pw1tpFONs8tClq4FxCr4AzuCMzLBsRnyOM3dcattTATdU-ahq5cjr4lPJNp2gkTrpgWUmqDEVQ8PBvYFB1LdWJpojxRIC24lv0GkQSSqdrct41UGHfDjhnPfI1mV945NgVJSfebhJP7O0GWxP9o9g_4svDCKa2LtCRbo7nDfWLeiE9fGULhmuJDjefAFZ5VMiYj8SrA4QtZXIu8jUQSQT89VYEP8PuG2hS_wMr0TL_GmcvEhNzQ8psPpPWFYhmSo“> https://graph.facebook.com/oauth/access_token?client_id=523007704381837&redirect_uri=http%3a%2f%2ffree-rsvp.com%3a80 %2fAccount%2fExternalLoginCallback%3fReturnUrl%3D%252FDashboard%26_ 提供商 _%3dFacebookPro%26_ SID _%3da80359b555c54b8f8d2f4f8e803f9125&client_secret = 212360b3ea6478fd0a0491e736b54256&代碼= AQCyTDStiB5gsQpKMx4uI1yFesVnLnWfE3u70VsB02-4HSyUCTbcf_3oHMo7QQI2as_pw1tpFONs8tClq4FxCr4AzuCMzLBsRnyOM3dcattTATdU-ahq5cjr4lPJNp2gkTrpgWUmqDEVQ8PBvYFB1LdWJpojxRIC24lv0GkQSSqdrct41UGHfDjhnPfI1mV945NgVJSfebhJP7O0GWxP9o9g_4svDCKa2LtCRbo7nDfWLeiE9fGULhmu JDjefAFZ5VMiYj8SrA4QtZXIu8jUQSQT89VYEP8PuG2hS_wMr0TL_GmcvEhNzQ8psPpPWFYhmSo
編輯帶我到Facebook的網址是:
provider_%253DFacebookPro%2526_ SID _%253Dbfe82f104ab34d1aa0f44c477c4d7819%26scope%3Demail%252Cuser_likes%252Cfriends_likes%252Cuser_birthday%252Cpublish_checkins%252Cpublish_stream%26client_id%3D523007704381837%26ret%3Dlogin&cancel_uri = HTTP%3A%2F%2Ffree-rsvp.com%2FAccount%2FExternalLoginCallback%3FReturnUrl% 3D%252FDashboard%26_ 提供程序 _%3DFacebookPro%26_ sid _%3Dbfe82f104ab34d1aa0f44c477c4d7819%26error%3Daccess_denied%26error_code%3D200%26error_description%3DPermissions%2Berror%26error_reason%3D&densed_3。 /login.php?skip_api_login=1&api_key=523007704381837&signed_next=1&next=https%3A%2F%2Fwww.facebook.com%2Fdialog%2Foauth%3Fredirect_uri%3Dhttp%253A%252F%252Ffree-rsvp.com%252FAccount%252FExternalLogin %252FDashboard%2526_ 提供程序 _%253DFacebookPro%2526_ sid _%253Dbfe82f104ab34d1aa0f44c477c4d7819%26scope%3Demail%252Cuser_likes%252Cfriends_likes%252Cuser_birthday%252Cpublish_checkins%252Cpublish_stream%26 d%3D523007704381837%26ret%3Dlogin&cancel_uri = http%3A%2F%2Ffree-rsvp.com%2FAccount%2FExternalLoginCallback%3FReturnUrl%3D%252FDashboard%26_ provider _%3DFacebookPro%26% sid _%3DBfe3%c%3%b2d3dbd3d3db2c3d3db2c3d3db2c3d4d3db2c3d0d%d3db1c3d3db2c3d3db3c0f0c人26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%23_%3D_&display = page
這是我的服務器端身份驗證代碼(MVC4項目)的一部分。 您應該查看的部分是如何相同地在“ Authorize”和“ AuthorizeCallback”函數中生成重定向URL,並將其傳遞給facebook客戶端:
[HttpPost]
public ActionResult Authorize(Guid eventId)
{
var @event = this.eventRepository.Find(eventId);
var redirectUri = ConfigurationProvider.HostingEndpoint + this.Url.Action("AuthorizeCallback", new { eventCode = @event.Code });
var service = new FacebookClient();
var loginUrl = service.GetLoginUrl(new {
client_id = ConfigurationProvider.FacebookAppId,
client_secret = ConfigurationProvider.FacebookAppSecret,
redirect_uri = redirectUri,
response_type = "code",
scope = "manage_pages, publish_actions, user_photos, publish_stream" // Add other permissions as needed
});
return new RedirectResult(loginUrl.AbsoluteUri, permanent: false);
}
public ActionResult AuthorizeCallback(string code, string eventCode, UserProfile userProfile)
{
var @event = this.eventRepository.Find(eventCode);
if (string.IsNullOrWhiteSpace(code) == true)
{
// means user clicked "cancel" when he was prompted to authorize the app
// todo: show some error message? or just redirect back?
return this.RedirectToAction("Event", "Dashboard", new { eventCode = @event.Code, feature = FeatureType.Update });
}
var redirectUri = ConfigurationProvider.HostingEndpoint + this.Url.Action("AuthorizeCallback", new { eventCode = @event.Code });
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = ConfigurationProvider.FacebookAppId,
client_secret = ConfigurationProvider.FacebookAppSecret,
redirect_uri = redirectUri,
code = code
});
var accessToken = result.access_token;
// update the facebook client with the access token so
// we can make requests on behalf of the user
fb.AccessToken = accessToken;
// Get the user's information
dynamic me = fb.Get("me");
return this.RedirectToAction("Event", "Dashboard", new { eventCode = @event.Code, feature = FeatureType.Update });
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.