【发布时间】:2016-11-15 13:47:56
【问题描述】:
我使用 django rest 框架和令牌身份验证作为后端身份验证。提交用户凭据时,来自后端令牌的格式为这种格式
{token: "cKCxxxxxxxxxxxxxxxxxxxxx"}
在前端 ember-simple auth 上,当我尝试登录时,我使用 oauth2 作为身份验证器:
身份验证器“authenticator:oauth2”拒绝恢复会话 - 正在失效……
并且会话未保存它已登录,但是当路由更改时它已注销。如何在标头中附加令牌?正确使用 ember-simple-auth 时必须自动附加它,否则我弄错了???
login.js
actions: {
authenticate(username, password) {
var controller = this.controller;
this.get('session').authenticate('authenticator:oauth2', username, password).catch((reason) => {
controller.set('errorMessage', reason.detail || reason);
console.log(this.get('session.data.authenticated'));
});
}
}
和验证者:
import OAuth2PasswordGrant from 'ember-simple-auth/authenticators/oauth2-password-grant';
export default OAuth2PasswordGrant.extend({
serverTokenEndpoint: 'http://127.0.0.1:8000/api/auth/login/',
});
授权人: 从 'ember-simple-auth/authorizers/oauth2-bearer' 导入 OAuth2Bearer;
export default OAuth2Bearer.extend({
});
适配器:
import DS from 'ember-data';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
export default DS.RESTAdapter.extend(DataAdapterMixin, {
host: 'http://127.0.0.1:8000',
namespace: 'api',
authorizer: 'authorizer:oauth2',
});
【问题讨论】:
标签: django authentication ember.js django-rest-framework ember-simple-auth