javascript - Microsoft Graph 令牌将在 1 天后过期
问题描述
我正在尝试将 Microsoft 令牌集成到我的应用程序中,但我有一个奇怪的错误,即使我每 30 分钟刷新一次令牌,它也会说令牌在 1 天后过期。我使用以下代码从用户那里获取令牌
const scope = e.target.dataset.scope;
var url = new URL("https://login.microsoftonline.com/common/oauth2/v2.0/authorize")
const params = {
client_id: '****',
response_type: 'code',
redirect_uri: `${Meteor.settings.public.__BASE_URL}/template/email-import`,
scope: 'user.read mail.read mail.readbasic mail.readwrite Mail.Send',
code_challenge: '****',
code_challenge_method: 'plain',
state: scope
}
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]))
window.location.replace(url);
之后,我使用访问令牌和刷新令牌捕获响应,并使用以下代码每 30 分钟刷新一次
const params = {
client_id: '****',
scope: 'user.read mail.read mail.readbasic mail.readwrite Mail.Send',
redirect_uri: Meteor.settings.public.__JTI_SERVER + '/template/email-import',
grant_type: 'refresh_token',
refresh_token: refreshToken,
}
var formData = new URLSearchParams();
for (var k in params) {
formData.append(k, params[k]);
}
const response = await fetch('https://login.microsoftonline.com/common/oauth2/v2.0/token', {
method: 'POST',
body: formData,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': Meteor.settings.public.__JTI_SERVER + '/template/email-import'
}
})
const json = await response.json();
if(json.error) {
throw new Error(`Error refreshing the token for company id ${company._id} and email ${company.email_details[scope].user_info.mail}`)
} else {
Company.update(company._id, {$set: {[`email_details.${scope}.microsoft_token`]: json }})
}
老实说,我正确地刷新了令牌,因为每次函数运行时我都会获得不同的访问和刷新令牌。但即便如此,令牌似乎在一天后过期,我无法在设置中找到更改它的位置。
我得到的完整错误日志是
{
error: 'invalid_grant',
error_description: 'AADSTS700081: The refresh token has expired due to maximum lifetime. The token was issued on 2021-05-23T09:51:53.7700436+00:00 and the maximum allowed lifetime for this application is 1.00:00:00.\r\n' +
'Trace ID: e0ae3ecc-1324-4ae5-823b-ed38e393a400\r\n' +
'Correlation ID: 409fd9ed-64c0-4f81-8ba7-546e6ceb2542\r\n' +
'Timestamp: 2021-05-26 07:30:01Z',
error_codes: [ 700081 ],
timestamp: '2021-05-26 07:30:01Z',
trace_id: 'e0ae3ecc-1324-4ae5-823b-ed38e393a400',
correlation_id: '409fd9ed-64c0-4f81-8ba7-546e6ceb2542',
error_uri: 'https://login.microsoftonline.com/error?code=700081'
}
如果有人可以提供帮助,将不胜感激。
提前致谢,
奥斯卡
解决方案
推荐阅读
- php - 图表代码点火器
- python - 混合两个图像,错误:图像不匹配
- c# - .NET v4.7 不存在 TLS1.2
- ruby-on-rails - “Bundler 找不到 gem 的兼容版本”,即使版本不冲突
- facebook - 如何从我自己的 facebook 页面获取所有专辑图片
- javascript - 在为循环中该选择器的所有实例选择(在任何选择器中)特定选项后,暂时禁用该选项
- firebase - 我有firebase云功能,当邮递员提出请求时,该功能最终工作,但当我收到颤振请求时出错
- r - dplyr 过滤器删除所有行
- c - 有没有办法在 VS 代码中进行就地 C 宏扩展?
- excel - Excel中消息框的选项