在app.js
我有一个AuthorizationInterceptor
来检查用户是否已登录。当用户令牌过期时,它会使用Frame window timed out
(见下文)遇到错误条件和错误,然后继续进入重定向循环。我想做一个无声的登录,但我猜iframe是错误的。我无法看到它重定向到silent-callback.html
- 它只会点击callback.html
:
app.factory("AuthorizationInterceptor", ['$q', '$injector', '$rootScope', '$window', 'authService', function ($q, $injector, $rootScope, $window, authService) {
var request = function (requestSuccess) {
var currentTime = Math.floor(Date.now() / 1000);
var deferred = $q.defer();
var oidcManager = window.translation.oidcUserManager;
oidcManager.getUser().then(function (u) {
if (u) {
if (u['expires_at'] < currentTime + 10) {
oidcManager.signinSilent()
.then(function (user) {
requestSuccess.headers['Authorization'] = "Bearer " + user["access_token"];
deferred.resolve(requestSuccess);
}, function (err) {
console.log('getuser error' + err); //this logs the below error.
authService.login();
deferred.resolve(true);
});
} else {
console.log('AuthInterceptor requestSuccess.headers');
requestSuccess.headers['Authorization'] = "Bearer " + u["access_token"];
deferred.resolve(requestSuccess);
}
}
else {
authService.login();
deferred.resolve(true);
}
});
return deferred.promise;
};
记录到控制台的错误消息:
getuser errorError: Frame window timed out app.js:92:41
Error: c.paramSerializer is not a function
p@http://localhost:5050/lib/angular/angular.min.js:88:204
n/h<@http://localhost:5050/lib/angular/angular.min.js:86:245
f/<@http://localhost:5050/lib/angular/angular.min.js:118:334
$eval@http://localhost:5050/lib/angular/angular.min.js:132:448
$digest@http://localhost:5050/lib/angular/angular.min.js:129:455
$evalAsync/<@http://localhost:5050/lib/angular/angular.min.js:133:30
e@http://localhost:5050/lib/angular/angular.min.js:43:93
Hf/l.defer/c<@http://localhost:5050/lib/angular/angular.min.js:45:491
这是authService.login()
var config = {
authority: url,
client_id: "js",
redirect_uri: url + "/LocalizationAdmin/callback.html",
response_type: "id_token token",
scope: "openid profile api1",
post_logout_redirect_uri: url + "/LocalizationAdmin/index.html",
silent_redirect_uri: url + "/LocalizationAdmin/silent-callback.html",
automaticSilentRenew: true
};
function login() {
mgr.getUser().then(function (u) {
if (u) {
var currentTime = Math.floor(Date.now() / 1000);
if (u['expires_at'] < currentTime + 10) {
mgr.signinSilent()
.then(function (user) {
var idToken = user.id_token;
var dataIdToken = getDataFromToken(idToken);
}, function (err) {
mgr.signinRedirect();
});
}
}
else {
mgr.signinRedirect();
}
});
非常坚持这一点 - 任何帮助表示赞赏。