我已经用我的SPA应用程序设置了adal和adal-角v.1.0.10库,并取得了很大的成功。我正在使用webpack,但是在我的html页面中引用这些内容是为了避免全局范围问题(尽管我希望它是一个依赖项)。直到浏览器尝试打开iframe来获取刷新令牌,并且每个iframe打开自己内部的另一个iframe为止,一切都是正常的。它没有记录错误,我也找不到关于我做错了什么的解释。因此,我被迫只在一个新的匿名浏览器中运行应用程序。我甚至想知道为什么会发生这种情况,因为我们已经和Azure AD很好地结婚了。
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('!');
}]);发布于 2016-06-08 12:18:01
在对GitHub进行了一系列的讨论之后,我注意到这是AuthenticationContext in adal.js的一个问题。它在尝试验证时一直打开iframe,导致无限循环。我通过公开AuthenticationContext让它工作起来。
var AuthenticationContext = require('expose?AuthenticationContext!./../Scripts/adal.js');
require('./../Scripts/adal-angular.js');这可能只适用于库的0.3.0版本。但现在已经足够了。希望将来他们能改变这个库,使之更好地与现代的js应用程序兼容。
发布于 2017-03-16 14:02:12
在'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");
...https://stackoverflow.com/questions/37211367
复制相似问题