【问题标题】:Adal Infinite redirection + Edge + Trusted sitesAdal 无限重定向 + Edge + 可信站点
【发布时间】:2017-04-07 23:17:18
【问题描述】:

背景: 我有一个单页应用程序(使用 Angular 构建),它使用 adal 和 adal-angular 对 Azure Active Directory 进行身份验证。 一直在使用 1.0.7 版本的 adal 和 adal-angular(也尝试使用 1.0.14 但仍然没有运气)和 ui-router 进行路由。

问题: 我们的用户中很少有人在尝试专门访问 Edge 浏览器上的 Web 应用程序时获得持续的身份验证循环。 请注意,它适用于 IE、Chrome 和 Firefox。令人惊讶的是,在 InPrivate 窗口中打开 Edge 时它也能正常工作。 此问题是特定于设备、特定于用户的,并且仅发生在 Edge 中。

解决方法: 当我的站点被添加到受信任站点时(通过控制面板 -> Internet 选项),身份验证循环问题得到解决,一切都可以无缝运行。

知道为什么会这样吗? 从我现在的假设来看,当 adal 将 auth cookie 写入站点而 Edge 似乎无法读取它时,这是一个 cookie 问题?

还有什么更好的修复/解决方法的建议吗?因为我不能告诉我所有的用户都去把我的网站添加到他们信任的网站集合中。

app.js 的代码 sn-p:

function authenticationInit(adalAuthenticationServiceProvider, $httpProvider, $locationProvider) {
$locationProvider.html5Mode(false);
var endpoints = {
// Map the location of a request to an API to a the identifier of the associated resource
"EndPointKey": window.config.aadEndPointUrl,
"EndPointValue": window.config.aadResouceIdUrl
};
    adalAuthenticationServiceProvider.init(
              {
                  instance: window.config.AADAuthenticationInstance,
                  tenant: window.config.tenant,
                  clientId: window.config.clientId,
                  extraQueryParameter: 'nux=1',
                  endpoints: endpoints
              }, $httpProvider);
}


function registerRoutes($stateProvider) {

    $stateProvider
        .state('home', {
            templateUrl: getViewUrl('widgets'),
            controller: 'WidgetsController',
            controllerAs: 'widget',
            url: '/dashboard'
        })
         .state('terms',
        {
            templateUrl: getViewUrl('terms'),
            controller: 'TermsController',
            controllerAs: 'terms',
            url: '/terms'
        })
}


$rootScope.$on('$locationChangeStart', function (e) {
if (adalAuthenticationService.userInfo.isAuthenticated == false) { // Will be executed during first time login and token expiration
adalAuthenticationService.login();
}
});


$rootScope.$on("adal:loginSuccess", function (e) { // Will be executed after AAD authentication is successful
NavigationFactory.navigateTo('home');
});

在这里提出了相同的查询-https://github.com/AzureAD/azure-activedirectory-library-for-js/issues/537

【问题讨论】:

  • 为了缩小此问题的范围,我建议调试代码以查看导致此问题的代码行。顺便说一句,您能否检查令牌是否已成功写入会话存储?
  • 经过进一步分析,我发现某些用户在 Edge 浏览器中将 cacheLocation 作为 sessionStorage 存在问题。对于某些用户,我可以在 sessionStorage 中看到 adal.error 为“Invalid_state”。在我的 adalAuthenticationServiceProvider.init 配置中将 cacheLocation 设置为 localStorage 后,问题已解决。由于 localStorage 自身的缺点和安全问题,我不喜欢使用它。到目前为止,我已经编写了条件代码,将 cacheLocation 设置为仅适用于 Edge 浏览器的 localStorage 和其他浏览器的 sessionStorage。有什么想法或更好的方法来解决这个问题?
  • 哪一行代码导致Invalid_state问题?由于该问题只能在特定用户上重现,因此它似乎与 Edge 的环境或设置有关。

标签: angularjs adal adal.js


【解决方案1】:

adal 使用 localStorage 保存令牌并稍后从中读取数据(您也可以选择将其更改为会话存储)。关键是,如果 adal 无法写入本地存储,您将无法获得令牌。 Microsoft Edge 中有一项设置可让网站存储数据。要启用此功能,请转到:设置>高级设置并启用:“让站点在我的设备上保存受保护的媒体许可证”。我希望这能解决您的问题。

【讨论】:

  • 所以我目前正在使用 sessionStorage 本身。如果您看到我的 adalAuthenticationServiceProvider.init 选项,我没有为 cacheLocation 指定任何内容,并且根据文档,默认情况下它是 sessionStorage,我认为它比使用 localStorage 更好。 Edge 读取 sessionStorage 有限制吗?
  • 我不是 100% 确定,但我认为它使用相同的标志。值得一试。
猜你喜欢
  • 2019-11-18
  • 2017-01-23
  • 2016-01-20
  • 1970-01-01
  • 1970-01-01
  • 2014-05-03
  • 2021-02-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多