gpt4 book ai didi

node.js - 无法从 oauth2 office365 日历 API 获取 token

转载 作者:搜寻专家 更新时间:2023-10-31 22:53:50 25 4
gpt4 key购买 nike

我无法从 office365 日历 API 获取 token ,过去 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);
}
});
}

在重定向到我的 rediredct Url 并将相同的代码传递给上面的函数“getTokenFromCode”后,我得到了代码,但我仍然收到错误,即“期待一个数组或一个可迭代的对象,但得到了 [object Null] ”。

请帮助我解决问题。提前致谢。

最佳答案

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

这会返回一个 promise 。希望对您有所帮助!

关于node.js - 无法从 oauth2 office365 日历 API 获取 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45370620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com