我已经撰写了一个用Angular编写的SPA,并且正在使用基于Azure AD令牌的身份验证以及通过持票人令牌保护的资源(如API)。这使得SPA能够从Azure中检索续订令牌,并永远保持登录状态,据我所知。ADAL JS强制注销SPA
我使用ADAL JavaScript库的角度来做到这一点:
https://github.com/AzureAD/azure-activedirectory-library-for-js
现在有限制的用户会话的时间预定量的要求,可以说15小时。
我写了一个不错的小服务,它在登录时存储cookie,每次请求它检查cookie中的日期以及它们是否超出其最大会话限制。如果用户持续使用应用程序或关闭浏览器,此功能可以正常工作 - 但如果他们将浏览器保持打开状态,令牌只会在后台更新,并且会保持登录状态。
我正在尝试解决此问题使用无声登出解决方案。这意味着,我希望用户在会话过期后被强制进入安全登录页面。
这似乎是一个常见的情况,但我似乎无法弄清楚如何实现它,因为ADAL在后台使用iFrame。我想过使用计时器/时间间隔,但似乎很麻烦。
只是FYI我按照下面的代码示例使用adalAuthenticationService.logout()。我也尝试清除会话缓存,这会起作用 - 但ADAL会默默刷新令牌。我也尝试将redirectUri位置设置为未经过身份验证的页面,但仍然只会在用户采取措施时重定向到那里。如果浏览器保持打开状态,令牌将自行重置。
var maxTime = 15; // hours allowed in session
// event to fire check; maybe this can be different, and is my problem?
$rootScope.$on('$viewContentLoaded', function() {
$scope.checkLogoutCookie();
});
$scope.logout = function() {
adalAuthenticationService.logout();
};
function setCookie(c) {} // implementation details don't matter....
function getCookie(c) {} // implementation details don't matter....
$scope.checkLogoutCookie = function() {
var lastLogin = getCookie("lastLogin");
var loginDate = new Date();
if (lastLogin === "") { // is empty
setCookie("lastLogin", loginDate, 365);
} else {
var lastDate = new Date(lastLogin);
var hours = Math.abs(lastDate - loginDate)/36e5;
if (hours > maxTime) {
setCookie("lastLogin", "", 0);
$scope.logout();
}
}
}
这不提供问题的答案。一旦你有足够的[声誉](https://stackoverflow.com/help/whats-reputation),你将可以[对任何帖子发表评论](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提问者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can- I-DO-代替)。 - [来自评论](/ review/low-quality-posts/17680085) –
是!谢谢你的提示。根据规则我改变了我的答案。 –