无法连接 Ember 简单身份验证和 DRF 令牌身份验证

Cannot connect Ember Simple Auth and DRF Token Auth

我在使用 Ember 简单验证时遇到问题。

我正在尝试连接使用 Django 1.9 和 DRF 的服务器端应用程序,以及使用 Ember 2.2.

的客户端

在服务器端,我在 'http://localhost:8000/api-token-auth/' 上获取令牌。函数需要来自请求的两个参数:"username""password"。但是 Ember Simple Auth 发送 POST 带有参数的请求:"username[identification]""password[password]",以及服务器 returns “400”。我认为参数键有问题。

POST request Responce 我尝试更改 oauth2-password-grant.js 中的 .authenticate 方法(我无法编写自定义身份验证器,因为我是 javascript 中的新手),但没有任何改变。

手动POST请求returns期望的答案。 请告诉我解决这个问题的方法。

请原谅我的英语。

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 };
authenticate: function () {
            // var username = this.getProperties('username');
            // var password = this.getProperties('password');

            const {username, password} = this.getProperties('username', 'password');

            this.get('session').authenticate('authenticator:oauth2', username, password).catch((reason) => {
                this.set('errorMessage', reason.error || reason);
            });
        }

这是我的错误。