5

I am not able to get token from office365 calendar API,From last 7 to 8 months it was working but suddenly I am getting the error "expecting an array or an iterable object but got [object Null]".

You guys can see my code here

 var oauth2 = require("simple-oauth2")(ConfigOutlookCredentials);
 var scopes = ["openid","offline_access","profile",     //here 'profile' is added bz not able to getting EmailId in this function getEmailFromIdToken.
   "https://outlook.office.com/mail.read",
   "https://outlook.office.com/calendars.readwrite"
 ];

function getTokenFromCode(auth_code,callback) {
   logger.MessageQueueLog.log("info","auth_code: "+auth_code+" || redirectUri: "+redirectUri+" || scopes: "+scopes);
   oauth2.authCode.getToken({
      code: auth_code,
      redirect_uri: redirectUri,
      scope: scopes.join(" ")
   }, function(error, result) {
    logger.MessageQueueLog.log("info","error: "+util.format('%j',error.message)+" || result: "+util.format('%j',result));
    if (error) { 
        return callback(error,null);
    } else {
         var token = oauth2.accessToken.create(result); 
         return callback(null,token);
    }
  });
}

I am getting code after redirecting to my rediredct Url and same code passing to above function "getTokenFromCode" ,still I m getting the Error i.e " expecting an array or an iterable object but got [object Null]".

Kindly help me to figure out the Issue. Thanks in Advance.

Santosh Khavekar
  • 597
  • 1
  • 6
  • 22

1 Answers1

0

I had the same error. You are using simple-oauth2-promise from https://github.com/jonathansamines/simple-oauth2

Solution for me was moving to https://github.com/lelylan/simple-oauth2 with a code like this:

var oauth2 = require('simple-oauth2').create({
            client: {
                id: service_data.clientID,
                secret: service_data.clientSecret
            },
            auth: {
                tokenHost: service_data.site,
                tokenPath: service_data.tokenPath
            }
        }

    );

    var tokenConfig = {
        code: data.code,
        redirect_uri: data.redirect_uri
    };

    return oauth2.authorizationCode.getToken(tokenConfig);

this returns a promise. hope it helps!