我正在使用django和angularjs开发一个项目,在那里我需要使用djangorestframework-jwt进行身份验证。我对djangorestframework-jwt很陌生。我使用‘/api-令牌-auth/’登录,但我没有任何用户信息。
我的认证服务是:
function login (username, password, callback) {
return $http.post('/api-token-auth/', {
username: username, password: password
}).then(loginSuccessFn(callback), loginErrorFn);
function loginSuccessFn (callback) {
return function (data, status, headers, config, response) {
localStorage.setItem('empee.token',data.data.token);
$http.defaults.headers.common['Authorization'] = 'Bearer ' + data.data.token;
if (typeof callback !== 'undefined') {
callback();
}
}
}
function loginErrorFn (data, status, headers, config) {
console.error('Epic failure!');
}
}登录控制器:
function login() {
Authentication.login(vm.username, vm.password, function() {
$state.go('dashboard');
});
}发布于 2016-02-27 12:21:19
考虑到在Django-rest框架中公开了用户URL,您可以执行$http.get。
$http.get('/user-url/'+userid).then(function(response){
if(response.status === 200){
user_obj = response.data;
}
});要获得userId,您只需使用角jwt即可
userid = jwtHelper.decodeToken(token).user_id;https://stackoverflow.com/questions/35666235
复制相似问题