node.js – 无法从oauth2 office365 calendar API获取令牌

我无法从office365日历API获取令牌,从最近7到8个月它正在工作但突然我得到错误“期望一个数组或一个可迭代的对象,但得到[对象空]”.

你们可以在这里看到我的代码

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);
    }
  });
}

我在重定向到我的rediredct Url并且相同的代码传递到上面的函数“getTokenFromCode”后得到代码,我仍然得到错误,即“期望一个数组或一个可迭代对象,但得到[对象为空]”.

请帮我弄清楚问题.
提前致谢.

解决方法

我有同样的错误.您正在使用 https://github.com/jonathansamines/simple-oauth2的simple-oauth2-promise

我的解决方案是使用如下代码移至https://github.com/lelylan/simple-oauth2

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);

这会返回一个承诺.希望能帮助到你!

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...