如何在angularjs中使用django rest framework jwt成功进行身份验证后获取用户信息

如何在angularjs中使用django rest framework jwt成功进行身份验证后获取用户信息,angularjs,django,authentication,django-rest-framework,Angularjs,Django,Authentication,Django Rest Framework,我正在与django和angularjs合作的一个项目中,我需要使用djangorestframework jwt进行身份验证。我是djangorestframework jwt的新手。我使用“/api token auth/”进行登录,但我没有获得任何用户信息 我的身份验证服务是: function login (username, password, callback) { return $http.post('/api-token-auth/', {

我正在与django和angularjs合作的一个项目中,我需要使用djangorestframework jwt进行身份验证。我是djangorestframework jwt的新手。我使用“/api token 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');
        });
    }

考虑到您在Django rest框架中公开了用户URL,您可以执行$http.get

$http.get('/user-url/'+userid).then(function(response){
    if(response.status === 200){
        user_obj = response.data;
    }
});
要获取userId,您只需输入userId即可


考虑到您在Django rest框架中公开了用户URL,您可以执行$http.get

$http.get('/user-url/'+userid).then(function(response){
    if(response.status === 200){
        user_obj = response.data;
    }
});
要获取userId,您只需输入userId即可


谢谢你的回答。我阅读了angular jwt文档,但不明白如何使用它。你能给我举个例子或详细解释一下吗?我得到了答案。再次感谢。这是否意味着无法从django rest framework jwt获取用户?需要另一个应用程序来获取用户id吗?我知道这有点过分,但我找不到其他方法。谢谢你的回答。我阅读了angular jwt文档,但不明白如何使用它。你能给我举个例子或详细解释一下吗?我得到了答案。再次感谢。这是否意味着无法从django rest framework jwt获取用户?需要另一个应用程序来获取用户id?我知道这有点过分,但我找不到其他方法。你说你解决了这个问题。解决办法是什么?假设公认的解决方案不是你怎么做的,你说你解决了这个问题。解决办法是什么?假设被接受的解决方案不是你怎么做的。