Can not authorise user in Facebook JS SDK : “This authorization code has been used.” or how to get new authorisation token?

旧城冷巷雨未停 提交于 2019-12-04 23:06:50

问题


I am trying to use Facebook to authenticate users. It works ok except for Ajax calls. Most of the times it just send old token and I get :

{"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100}}

So what I tried doing is wrapping every ajax call with

FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            return  fn();
            ...

this did not worked so I've added : true as parameter to getLoginStatus to prevent caching :

FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            console.log('connected');
            fn();
        } else if (response.status === 'not_authorized') {
            console.log('not_authorized);
        } else {
            console.log('not_logged_in');
        }
    },true);

Great! Except it is terribly slow. Am I doing something wrong? Can I get new token after each action so I do not need to wait before the next one?

Thanks W


回答1:


Here's what Facebook says:

"New security restrictions for OAuth authorization codes. We will only allow authorization codes to be exchanged for access tokens once and will require that they be exchanged for an access token within 10 minutes of their creation. This is in line with the OAuth 2.0 Spec which from the start has stated that "authorization codes MUST be short lived and single use". For more information, check out our Authentication documentation.

The way around this is to use the extending your access token api:

https://developers.facebook.com/docs/howtos/login/extending-tokens/



来源:https://stackoverflow.com/questions/16224141/can-not-authorise-user-in-facebook-js-sdk-this-authorization-code-has-been-us

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!