我使用角-http-auth在角-js应用程序中进行身份验证。
以下是登录控制器中的登录函数:
$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是来自这里的加密服务)
问题是:如果用户已经登录并且打开了一个新的选项卡,或者如果他重新加载页面,他必须再次登录。
如果用户重新加载页面或来自外部链接,如何才能避免这种情况并保持会话打开?
发布于 2013-09-29 10:09:51
您可以使用cookies或html5数据存储来保存凭据或带有凭据的base64字符串。然后,您可以从那里加载它们,并将它们解析为$http.defaults.head ers.Common‘’Authorization‘= 'Basic’+凭据;
希望能帮上忙。
https://stackoverflow.com/questions/19076445
复制相似问题