【发布时间】:2015-12-08 21:37:09
【问题描述】:
我在使用 Ember 简单身份验证时遇到问题。
我正在尝试连接在 Django 1.9 上使用 DRF 运行的服务器端应用程序,以及在 Ember 2.2 上运行的客户端。
在服务器端,我在'http://localhost:8000/api-token-auth/' 上获取令牌。函数需要来自请求的两个参数:"username" 和 "password"。但是 Ember Simple Auth 发送带有参数的 POST 请求:"username[identification]" 和 "password[password]",服务器返回“400”。我认为参数键的问题。
POST request Responce 我尝试更改 oauth2-password-grant.js 中的 .authenticate 方法(我无法编写自定义身份验证器,因为我是 javascript 中的新手),但没有任何改变。
手动 POST 请求返回预期答案。 请告诉我解决这个问题的方法。
请原谅我的英语。
authenticate(identification, password, scope = []) {
return new RSVP.Promise((resolve, reject) => {
const data = { 'grant_type': 'password', username: identification, password };
const serverTokenEndpoint = this.get('serverTokenEndpoint');
const scopesString = Ember.makeArray(scope).join(' ');
if (!Ember.isEmpty(scopesString)) {
data.scope = scopesString;
}
this.makeRequest(serverTokenEndpoint, data).then((response) => {
run(() => {
const expiresAt = this._absolutizeExpirationTime(response['expires_in']);
this._scheduleAccessTokenRefresh(response['expires_in'], expiresAt, response['refresh_token']);
if (!isEmpty(expiresAt)) {
response = Ember.merge(response, { 'expires_at': expiresAt });
}
resolve(response);
});
}, (xhr) => {
run(null, reject, xhr.responseJSON || xhr.responseText);
});
});
},
我的变种:
const data = { 'grant_type': 'password', 'username': identification, 'password': password };
【问题讨论】:
标签: django-rest-framework ember-simple-auth