【发布时间】:2013-10-05 06:24:37
【问题描述】:
我在 angular-js 应用程序中使用 angular-http-auth 进行身份验证。
这是登录控制器内部的登录功能:
$scope.login = function() {
var credentials = Base64.encode($scope.username + ':' + $scope.password);
var config = { headers: { 'Authorization': 'Basic ' + credentials } };
$http.get('url/to/json/user', config)
.success(function() {
$http.defaults.headers.common['Authorization'] = 'Basic ' + credentials;
authService.loginConfirmed();
console.log('login success');
})
.error(function() {
console.log('login failed');
});
}
(base64是来自here的加密服务)
问题:如果用户已经登录并且他打开了一个新选项卡,或者如果他重新加载页面,他必须再次登录。
如果用户重新加载页面或来自外部链接,如何避免这种情况并保持会话打开?
【问题讨论】:
-
请注意:base64 是编码,不是加密。它很容易可逆,无需密钥,因此会混淆身份验证信息,并使其免受其他编码问题(如 HTTP 编码)的影响,但不会增强安全性。
标签: session angularjs http-authentication