【问题标题】:Unable to get Token from oauth2 office365 calendar API无法从 oauth2 office365 日历 API 获取令牌
【发布时间】:2017-09-29 11:16:39
【问题描述】:

我无法从 office365 日历 API 获取令牌,从过去 7 到 8 个月它一直在工作,但突然我收到错误“期望数组或可迭代对象但得到 [object Null]”。

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

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

我在重定向到我的重定向 URL 和相同的代码传递给上述函数“getTokenFromCode”后得到代码,但我仍然得到错误,即“期望一个数组或一个可迭代对象但得到 [object Null]强>”。

请帮助我找出问题所在。 提前致谢。

【问题讨论】:

    标签: node.js oauth-2.0 calendar access-token office365api


    【解决方案1】:

    我有同样的错误。您正在使用来自 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);
    

    这会返回一个承诺。 希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2015-02-11
      • 1970-01-01
      • 2017-04-04
      相关资源
      最近更新 更多