auth自定义授权器未调用

auth自定义授权器未调用

本文介绍了Ember-simple-auth自定义授权器未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ember-simple-auth实现自定义验证,我一开始就坚持下去。我有app / autheticators / digest.js

I'm trying to implement custom auth with ember-simple-auth and I stuck at the start. I have app/autheticators/digest.js

import Base from 'ember-simple-auth/authenticators/base';
import Ember from 'ember';

export default Base.extend({
  restore(data) {
    //
  },
  authenticate(email, password) {
    console.log(email, password);
    return new Ember.RSVP.Promise(function(resolve, reject) {
      Ember.run(function() {
          resolve({email: email, password: password});
        });
    });
  },
  invalidate(data) {
    //
  }
});

app / authorizers / digest.js

app/authorizers/digest.js

import Base from 'simple-auth/authorizers/base';
import Ember from 'ember';

export default Base.extend({
  header: function() {
    return "test-digest";
  },

  authorize: function(sessionData, block) {
    console.log('authorize...');
    block('Authorization', this.get('header'));
  }
});

登录组件:

import Ember from 'ember';
import CryptoJS from 'npm:crypto-js';

export default Ember.Component.extend({
    session: Ember.inject.service('session'),
    actions: {
        login() {
            let { email, password } = this.getProperties('email', 'password');
            this.get("session").authenticate('autheticator:digest',
                email, CryptoJS.SHA256(password).toString()).catch((reason) => {
                this.set('errorMessage', reason.error);
            });
        }
    }

});

验证正确(我希望),但授权者中没有调用授权。我还尝试向ENV添加一些值:

Authentication called properly (I hope), but "authorize" in authorizer never called. I also tried add some values to ENV:

  ENV['simple-auth'] = {
    authorizer: 'authorizer:digest',
    crossOriginWhitelist: ['http://prod-drunkedguru.rhcloud.com:80/'] // ['*'] I also tried
  };

但没有改变。我做错了什么?

But nothing changed. What I'm doing wrong?

我正在使用EAS 1.0的EmberJS 1.13.0。

P.S. I'm using EmberJS 1.13.0 with EAS 1.0.

推荐答案

我假设您使用的是ESA 1.0。在该版本中,授权者不会自动调用,但需要手动调用它。有可用于自动授权Ember Data请求的 DataAdapterMixin 。有关迁移到1.0的指导,请参阅此博文:

I assume you're using ESA 1.0. In that version the authorizer isn't automatically called anymore but you need to call it manually. There is the DataAdapterMixin that you can use to automatically authorizer Ember Data requests though. See this blog post for guidance on migrating to 1.0: http://log.simplabs.com/post/131698328145/updating-to-ember-simple-auth-10

这篇关于Ember-simple-auth自定义授权器未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 15:54