【发布时间】:2015-06-21 07:54:12
【问题描述】:
我正在学习使用令牌在 angular.js 前端对用户进行身份验证。
我正在使用以下包(对 Django REST 框架的 JSON Web 令牌身份验证支持)
https://github.com/GetBlimp/django-rest-framework-jwt
我已经实现了所有设置,示例 curl 请求工作正常。
现在我有一个带有 angularjs 的登录页面,它发布到 rest 端点,如下面的代码所示:
$http
.post('/api-token-auth/', {email: $scope.account.email, password: $scope.account.password})
.then(function(response) {
// assumes if ok, response is an object with some data, if not, a string with error
// customize according to your api
if ( !response.account ) {
$scope.authMsg = 'Incorrect credentials.';
}else{
$state.go('dashboard');
}
}, function(x) {
$scope.authMsg = 'Server Request Error';
});
现在,当我发布电子邮件和密码时,在回复中我会得到这样的成功令牌
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InNhbXBsZUBzYW1wbGUuY29tIiwidXNlcl9pZCI6MSwiZW1haWwiOiJzYW1wbGVAc2FtcGxlLmNvbSIsImV4cCI6MTQyOTA5NjM5N30
.w0XV1kArTyZY9iCPyr2LmRzToD9iOgYlMVCoXmdOJ1A"}
现在我对代币不太了解,我想知道接下来我应该做什么?我的意思是在获得令牌后如何登录用户并将该用户放入一些 userObject 角度。
【问题讨论】:
标签: django angularjs rest django-rest-framework