无法连接Ember Simple Auth和DRF Token Auth

时间:2015-12-08 21:37:10

标签: django-rest-framework ember-simple-auth

我在使用Ember Simple Auth时遇到了麻烦。

我试图连接我的服务器端应用程序,该应用程序在Django 1.9上运行DRF,而客户端则运行在Ember 2.2上。

在服务器端,我在'http://localhost:8000/api-token-auth/'上获取令牌。功能需要两个来自请求的参数:"username""password"。但Ember Simple Auth使用args发送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 };

1 个答案:

答案 0 :(得分:0)

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);
            });
        }

这是我的错误。

相关问题