oauth2-extensions
oauth2-extensions copied to clipboard
Adapter sill loading twice
I've been looking at ways to fix this, but I'm not sure if there are multiple ways to call it, but if you do something like:
var github = new OAuth2('github', .....); github.authorize(function(){...});
This will load up two versions of the adapter as when they get called, they basically get called at the same time and the line of:
if (OAuth2.adapters[adapterName]) { callback(); return; }
is null. I added the code console.log(OAuth2.adapters[adapterName]); right above and it comes up with undefined.
Now if I do something like:
var github = new OAuth2('github', .....); setTimeout(auth, 5); function auth(){ github.authorize(function(){...}); }
Then the console.log(OAuth2.adapters[adapterName]) will display undefined and then the object, so at that time only one adapter will load. I'm trying to think of a way to fix this, but I'm stuck.
I'm not seeing multiple adapters being loaded. The line you quote above: if (OAuth2.adapters[adapterName]) {
should prevent the adapter from being loaded twice. Could you please provide a full code sample with the adapter loaded twice?
Here is my code for popup.js
var fsq = new OAuth2('foursquare', { client_id:'C2BDAF4Y2QOC5RWAIRC0TYOVLRIBRAWX3DLDUYTF5XOPNTVG', client_secret:'Z5GLOY3ZIKC3HF2DYQU3YSYFS2OII2J2JUQYJPASIF10BJ0V' });
fsq.authorize(function() { alert(fsq.getAccessToken()); alert(fsq); });
If you look at the "View Source" it only loads once. If you do an inspect element and check, it loads twice. Like I tried to say, if added a 5ms setTimeout it would only load once. It all has to do with the timing in js.
On line 258, without the timeout, the value is null, so the adapter gets loaded once when you create the object and a second time when you run the authorize function.