2016-05-13 42 views
2

我已经用我的SPA应用程序设置了adal和adal-angular v.1.0.10库,并取得了很大的成功。我正在使用webpack,但在我的html页面中引用这些信息,希望避免全局范围问题(尽管我希望它是一个依赖项)。一切正常,直到浏览器尝试打开一个iframe以获取刷新标记,并且每个iframe在其内部打开另一个iframe。它没有记录任何错误,而且我也找不到解释我做错了什么。所以我不得不在新的隐身浏览器中运行应用程序。即使有解释为什么会发生这种情况,我也会很感激,因为我们很熟悉Azure AD。Adal和Adal-Angular - 刷新令牌无限循环

的index.html的相关章节

<md-button aria-label="Login" ng-if="!userInfo.isAuthenticated" ng-click="login()"> 
    Login 
</md-button> 

<script src="build/app.bundle.js" charset="utf-8"></script> 
<script src="Scripts/adal.min.js" charset="utf-8"></script> 
<script src="Scripts/adal-angular.min.js" charset="utf-8"></script> 

我app.js

angular.module('myApp', ['AdalAngular', require('angular-route'), require('angular-animate'), require('angular-sanitize'), 'ngCookies', etc..]) 
    .config(['$routeProvider', '$locationProvider', '$mdThemingProvider', '$httpProvider', 'adalAuthenticationServiceProvider', 
    function ($routeProvider, $locationProvider, $mdThemingProvider, $httpProvider, adalProvider) { 

     // azure ad init 
     adalProvider.init({ 
      instance: 'https://login.microsoftonline.com/', 
      tenant: TENANT, 
      clientId: CLIENTID, 
      cacheLocation: 'localStorage', 
      anonymousEndpoints: [] 
     }, 
     $httpProvider 
    ); 

     $routeProvider 
     .when('/home', { 
     templateUrl: '/App/Layout/home.html' 
     }) 
     .when('/admin', { 
     templateUrl: '/App/Admin/admin.html', 
     requireADLogin: true 
     }) 
     etc... 

     $locationProvider.html5Mode(true).hashPrefix('!'); 

    }]); 
+0

这似乎是adaljs中的问题。看到这[问题在他们的github页面](https://github.com/AzureAD/azure-activedirectory-library-for-js/issues/216)和这[相关的SO问题](http://stackoverflow.com/问题/ 34686460 /阿达尔-JS-随机数 - 是 - 不一样-AS-未定义/)。你有没有找到解决方法?我遇到了完全相同的行为,并且这些链接中的信息不幸地证明了卓有成效。 – Bryan

回答

0

经过了漫长的系列GitHub上的讨论,它引起了我的注意,这是一个问题与Adal.js中的AuthenticationContext它在尝试验证时会一直打开iframe,导致无限循环。我通过暴露AuthenticationContext来实现它。

var AuthenticationContext = require('expose?AuthenticationContext!./../Scripts/adal.js'); 
require('./../Scripts/adal-angular.js'); 

这可能只适用于库的版本0.3.0版本。但现在已经够好了。希望他们将在未来改变图书馆,使其与现代js应用更加兼容。

+0

只是想补充说,从1.0.11开始,这仍然是一个问题,尽管他们努力阻止无限循环。它仍然必须依附于js的全球范围。我继续留意并希望我被迫使用的过时版本不会过时。 –

0

在'getRequestInfo'方法中的adal.js中,iframe将'查找'到AuthenticationContext的父级。这意味着AuthenticationContext必须位于窗口范围内。

//ES6 
import AuthenticationContext from "adal-angular/lib/adal"; 
window.AuthenticationContext = AuthenticationContext; 
... 

//ES5 
window.AuthenticationContext = require("adal-angular/lib/adal"); 
...