0

I'm trying to use Outlook's API and I'm using simple-oauth2 to authorize permissions. I'm grabbing snippets from Microsofts Doc's but I get the following error:

Error getting token [object Object]

...

TypeError: Cannot read property 'send' of null at tokenReceieved

I have a function that directs me to the Azure's login page:

app.get('/authorize', (req, res) => {
  console.log("Request handler 'authorize' was called.");

  const { code } = req.query;
  // The authorization code is passed as a query parameter

  console.log(`Code: ${code}`);
  authHelper.getTokenFromCode(code, tokenReceived, res);
});

which calls getTokenFromCode from a seperate file:

function getTokenFromCode(auth_code, callback, response) {
  var token;
  oauth2.authorizationCode.getToken(
    {
      code: auth_code,
      redirect_uri: redirectUri,
      scope: scopes.join(' ')
    },
    function(error, result) {
      if (error) {
        console.log('Access token error: ', error.message);
        callback(response, error, null);
      } else {
        token = oauth2.accessToken.create(result);
        console.log('Token created: ', token.token);
        callback(response, null, token);
      }
    }
  );
}

But the problem is at tokenRecieved:

const tokenReceived = (req, res, error, token) => {
  if (error) {
    console.log(`Error getting token ${error}`);
    res.send(`Error getting token: ${error}`);
  } else {
    req.session.access_token = token.token.access_token;
    req.session.refresh_token = token.token.refresh_token;
    res.redirect('/logincomplete');
  }
};
  • Can you change `console.log("Error getting token ${error}");` to `console.log("Error getting token", error);`? You should see the object structure of `error` – Luca Kiebel Jan 23 '18 at 17:48
  • Hey Luca, seems to return the same. I didn't add this to the original post but the issue is pointing to a specific line from the bluebird module: `fn = function () { throw arg; };` –  Jan 23 '18 at 17:58

0 Answers0