javascript - ADAL.js - "Nonce is not same as undefined"

标签 javascript azure single-page-application azure-active-directory adal

我目前在使用 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/

相关文章:

javascript - WinJS.xhr 返回 XML 字符串作为文本(包括\n\r 标记),而不是 responseXML

asp.net - Windows Azure 访问控制和 WPF?

azure - 使用流分析将数据插入 CosmosDB

javascript - DurandalJS 路由行为

javascript - EventEmitter <string> 的上下文 'this' 未分配给 Observable <string> 类型的 'this' 方法

javascript - 如何在 jQuery 集合中获取被点击的项目索引?不是通过索引()

javascript - 用于匹配 unicode 字符的正则表达式,除非在单词末尾使用

javascript - 为什么调用此 Javascript 函数会提交我的表单?

azure - 为多个订阅创建 Azure 服务主体

wordpress - 单页应用程序适合写博客吗?