我目前在使用 ADAL.js (v1.0.7) 库时遇到问题。当我在一段相当长的时间后加载我的应用程序时,我收到登录错误,指出“Nonce 与未定义不同”。查看代码后,我想知道我是否缺少最佳实践。据我所知,我遵循了@vibronet here的建议。我应该刷新用户个人资料、注销还是其他什么?
我的配置如下:
window.config = {
instance: 'https://login.microsoftonline.com/',
tenant: 'blahblahblah.onmicrosoft.com',
clientId: 'GUID',
postLogoutRedirectUri: window.location.origin,
cacheLocation: 'localStorage'
};
this.authContext = new window.AuthenticationContext(window.config);
var isCallback = this.authContext.isCallback(window.location.hash);
this.authContext.handleWindowCallback();
if (isCallback && !this.authContext.getLoginError()) {
window.location = this.authContext._getItem(this.authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
}
如果长时间处于不活动状态,则调用 this.authContext.login() 后会发生错误。为了获取错误,我调用 this.authContext.getLoginError()。
我明白为什么随机数不同,但我想“重置”它或导致发生全新的登录。
请告诉我我还可以提供哪些其他相关信息。
最佳答案
更新:
您提供的博客文章中似乎已经提供了解决方案。以下是报价。
The trick is to go back to the authority asking for a token, like we’d do in the roundtrip apps scenario, but doing so in a hidden iframe. If there is still an existing session with the authority (which might be represented by a cookie – but it is a cookie in the domain of the authority, NOT the app’s) we will be able to get a new token without any UX. There is even a specific parameter, prompt=none, which lets Azure AD know that we want to get the token without a UX, and if it can’t be done we want to get an error back. Here there’s the request.
之前的回答:
我没有完全遵循您的代码的作用。但从博客文章来看,似乎在下面您正在使用 OAuth 2.0
当您说一段时间不活动时会发生错误时,我的猜测是 token 已无效,您需要刷新 token 。不知道有没有办法让你刷新一下。但通常在服务器端,一旦您进行了身份验证,OAuth 2.0 提供程序将向您提供一个 token 和一个刷新 token ,如果 token 过期,您可以使用刷新 token 来获取新 token 。
关于javascript - ADAL.js - "Nonce is not same as undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34686460/