question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ms-rest-azure.interactiveLogin callback always returns 'authorization_pending' error (in React Electron)

See original GitHub issue

Issue:

When I call interactiveLogin, my callback is almost immediately called and it’s given an error: authorization_pending.

This seemed strange to me, because it seems like it normally waits around for a bit when I’m doing a normal Node application, but I’m doing an Electron application and this call is actually taking place in a React component. I dove down through adal-node code, etc., but it doesn’t look like they handle retry/etc. I felt like maybe this method should be attempting to retry for me.

Workaround:

I decided the way of getting around this for now is to add retry, so I ended up modifying interactive login to have retry baked into the acquireTokenWithDeviceCode step. Not necessarily the cleanest code, but it works now. 😃

  // will retry until a non-pending error is returned or credentials are returned.
  var tryAcquireToken = function (userCodeResponse, callback) {
      self.context.acquireTokenWithDeviceCode(self.environment.activeDirectoryResourceId, self.clientId, userCodeResponse, function (err, tokenResponse) {
        if (err) {
          if(err.error === 'authorization_pending'){
            setTimeout(()=>{
              tryAcquireToken(userCodeResponse, callback);
            }, 1000);
            return
          } else {
            return callback(err);
          }
        }
        self.username = tokenResponse.userId;
        self.authorizationScheme = tokenResponse.tokenType;
        return callback(null);
      });
  }

  async.waterfall([
    //acquire usercode
    function (callback) {
      self.context.acquireUserCode(self.environment.activeDirectoryResourceId, self.clientId, self.language, function (err, userCodeResponse) {
        if (err) return callback(err);
        if (self.userCodeResponseLogger) {
          self.userCodeResponseLogger(userCodeResponse.message);
        } else {
          console.log(userCodeResponse.message);
        }
        return callback(null, userCodeResponse);
      });
    },
    //acquire token with device code and set the username to userId received from tokenResponse.
    tryAcquireToken,

/* nothing else changed from here... */

Not entirely sure if supporting Electron is actually important for ya’ll. I’ll likely just create a fork or a custom library for my purposes. I also had to create a custom version of adal-node which didn’t read in the package.json from a relative directory. Just thought I’d raise this here since it did take a good couple of hours out of my day.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
amarzaverycommented, Sep 29, 2017

Update: A newer version of “ms-rest-azure”: “2.3.5” has been published which takes an explicit dependency on async version 2.5.0 and has the retry logic baked into it. Hope this should resolve the issue. Let us know if you find more issues.

0reactions
amarzaverycommented, Sep 27, 2017

Ah I see. We will investigate further by bumping the version of async. If everything passes then we will take a dependency on newer version of async. Btw, We are working towards creating an isomorphic js library that works in node.js environment and browser too. We have created a new library called ms-rest-nodeauth that focuses on node.js based authentication. This library does not use async library. It is written in typescript with latest ES6 and ES7 features (async/await, promises, etc.). It also supports callback for backwards compatibility. Give it a try and let us know if you have any issues with that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ms-rest-azure.interactiveLogin callback always returns ...
Issue: When I call interactiveLogin, my callback is almost immediately called and it's given an error: authorization_pending.
Read more >
Electron & ReactJS, Use BrowserWindow for GitHub oAuth ...
So when a user presses the Login with Github button, a new BrowserWindow opens and goes to the github authorize app url. The...
Read more >
Hooks API Reference - React
React guarantees that setState function identity is stable and won't change on re-renders. This is why it's safe to omit from the useEffect...
Read more >
The Ultimate Guide to Electron with React - Medium
In this article, we'll learn how to implement powerful features of Electron with React. By the end of the article, you will be...
Read more >
Electron with React JS under 40 min! - YouTube
... https://academy.eincode.com/ Full Course: https://academy.eincode.com/courses/ electron - react -js-build-native-chat-app-with-javascript ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found