【发布时间】:2015-08-29 18:18:15
【问题描述】:
我正在使用这个
http://getblimp.github.io/django-rest-framework-jwt/#refresh-token
我很困惑如何使它工作。我已经完成了所有设置。现在如何使它工作。
目前我有代码在用户提交登录时获取第一个令牌,并将该令牌保存在 cookie 存储中。然后我的请求将该令牌用于所有请求。我已经看到该令牌有时会过期,我不希望那样。所以这就是我使用这个的原因
$http
.post('/api-token-auth/', logData)
.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.data.token) {
_vm.authMsg = 'Incorrect credentials.';
deferred.reject('Incorrect credentials.');
} else {
$cookieStore.put('djangotoken', response.data.token);
$http.defaults.headers.common.Authorization = 'JWT ' + response.data.token;
$http.get('/api/account/restricted/').then(function (response) {
authService.loginConfirmed();
$cookieStore.put('currentUser', response.data);
$rootScope.$broadcast('user:login');
});
}
deferred.resolve(response.data);
}, function (x) {
_vm.authMsg = 'Server Request Error';
deferred.reject('Server Request Error');
});
这就是我在每个请求中使用该令牌的方式
$http.defaults.headers.common['Authorization'] = 'JWT ' + $cookieStore.get('djangotoken');
现在需要做什么才能使刷新令牌起作用。我的意思是用户是否必须手动刷新令牌或系统会自动刷新。我什么时候需要访问这个网址
url(r'^api-token-refresh/', 'rest_framework_jwt.views.refresh_jwt_token'),
【问题讨论】:
标签: angularjs django rest django-rest-framework jwt