2017-07-28 103 views
5

我無法從office365日曆API獲取令牌,從最近7到8個月它正在工作,但突然間我收到錯誤「期待數組或迭代對象,但得到了[對象爲空]「。無法從oauth2獲取令牌office365日曆API

你們可以在這裏看到我的代碼

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地址和相同的代碼傳遞給上面的函數「getTokenFromCode」後獲得的代碼,我仍m到處錯誤,即「期待的數組或可迭代的對象,但得到[對象爲空]「。

請幫助我找出問題。 在此先感謝。

回答

0

我有同樣的錯誤。

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

這將返回一個承諾:我將移居https://github.com/lelylan/simple-oauth2有這樣的代碼,你正在使用從https://github.com/jonathansamines/simple-oauth2

解決簡單的oauth2-承諾。 希望它有幫助!