2017-07-28 19 views
5

Tôi không thể nhận mã thông báo từ API lịch office365, Từ 7 đến 8 tháng qua, nó hoạt động nhưng đột nhiên tôi gặp lỗi "mong đợi mảng hoặc đối tượng có thể lặp lại nhưng đã nhận được [đối tượng Null] ".Không thể nhận mã thông báo từ oauth2 office365 lịch API

Các bạn có thể xem mã của tôi ở đây

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

Tôi nhận được mã sau khi chuyển hướng đến rediredct tôi Url và cùng một mã thông qua chức năng trên "getTokenFromCode", tôi vẫn đang nhận được Lỗi ie "mong đợi một mảng hoặc đối tượng có thể lặp lại nhưng nhận [đối tượng Null] ".

Vui lòng giúp tôi tìm ra sự cố. Cảm ơn trước.

Trả lời

0

Tôi đã gặp lỗi tương tự. Bạn đang sử dụng đơn giản-OAuth2-lời hứa từ https://github.com/jonathansamines/simple-oauth2

Giải pháp đối với tôi là chuyển sang https://github.com/lelylan/simple-oauth2 với một mã như thế này:

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

này trả về một lời hứa. hy vọng điều đó sẽ hữu ích!

Các vấn đề liên quan