oauth-io/oauth-js

Chrome Extension success not returning a result object

RichardLitt opened this issue · 3 comments

I'm working with a Chrome Extension, and finding it difficult to set OAuth.io up. I've tried two setups. The first involves adding oauth.js to background: { scripts: [...] } in the Chrome Extension manifest and then using the following code in the background.js file:

OAuth.initialize('key')
//Using popup
OAuth.popup('facebook')
    .done(function(result) {
      console.log('Success!', result)
      //use result.access_token in your API request
      //or use result.get|post|put|del|patch|me methods (see below)
    })
    .fail(function (err) {
      console.log('Error.', err)
      //handle error with err
});

The second has the oauth.js file added in the head of an index.html file I rerender PDFs in (basically, in the client), and then calling using the same code as above in the main.js, which is set as a content_script in the Chrome Extension manifest.

For both cases, the popup occurs immediately on load - for the first, on load of the extension, and for the second, on load of my index.html file. That's fine, I don't have them working on a click at the moment. The issue is that the pop up immediately closes, and the console log I from inside the callback returns Success! undefined, with no result object. I'm not sure what the deal is.

I do know that the pop up closing may be the problem - I never actually see any HTML render in it, and I certainly don't click anything or allow authentication on my end, which I ought to do if I'm dealing with an OAuth client. I have added the following, as outlined here to my manifest.json:

  "externally_connectable": {
    "matches": ["https://oauth.io/*"]
  },

But it doesn't seem to have changed anything. Any ideas?

I fixed a cause of the undefined result in 62a91ec (you can update oauth-js to master or 0.4.1) but i still have some hard time when using it in a browseraction: opening a window closes the extension popup and stops the script so it never goes in the callbacks unless the chrome inspector is open (this causes the ext popup to do not close itself).

Interesting. If I keep the chrome inspector open, I don't get any different functionality.

What is happening for me, now, is that I am getting an error response from Oauth.popup('facebook'):

Error: Origin "chrome-extension://cmanihjhjdpbdpdgjhbndmpicmkgfdga/" does not match any registered domain/url on oauth.io

I went into my Dashboard and added that URL. Now the pop up loads properly, but I am getting an error back from Facebook: "The parameter app_id is required." How do I send that from OAuth.io?

Scratch that. Got it working for GitHub, at least. Looks like this is all set - I'm not getting your bug at all, this seems to work.