gpt4 book ai didi

microsoft-identity-platform - CompactToken验证失败80049228

转载 作者:行者123 更新时间:2023-12-04 12:56:45 25 4
gpt4 key购买 nike

某些用户尝试使用Microsoft登录登录以通过MS Graph访问邮件时,会重新获得此错误。我有公司用户和个人(Hotmail.com)用户都显示此错误号,但是对于大多数用户来说,它工作正常。

这是电话:

https://login.microsoftonline.com/common/oauth2/v2.0/token

这是返回的错误:
Code: InvalidAuthenticationToken
Message: CompactToken validation failed with reason code: 80049228

有指针吗?在哪里可以找到该错误号的引用?

最佳答案

这意味着 token 已过期,需要刷新。如果要在没有用户交互的情况下刷新它,则需要一个refresh_token,该代码在最初获取 token 时会返回。

您可以通过以下方式刷新它:

function refreshTokenIfNeeded(tokenObj){
let accessToken = oauth2.accessToken.create(tokenObj);

const EXPIRATION_WINDOW_IN_SECONDS = 300;

const { token } = accessToken;
const expirationTimeInSeconds = token.expires_at.getTime() / 1000;
const expirationWindowStart = expirationTimeInSeconds - EXPIRATION_WINDOW_IN_SECONDS;

const nowInSeconds = (new Date()).getTime() / 1000;
const shouldRefresh = nowInSeconds >= expirationWindowStart;


let promise = Promise.resolve(accessToken)
if (shouldRefresh) {
console.log("outlook365: token expired, refreshing...")
promise = accessToken.refresh()
}
return promise
}

其中 tokenObj是您存储在数据库中的 token 对象。
确保它也具有 expires_at,否则 oauth2.accessToken.create()将创建它并从当前时间开始计算。

可以在 this tutorialthis github repo中找到更多详细信息(这是上面的代码的来源)

关于microsoft-identity-platform - CompactToken验证失败80049228,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53992822/

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