2017-04-20 85 views
0

我試圖使用ember-simple-auth和ember將JWT身份驗證實現到我的Ember應用程序中通過遵循GitHub上的自述文件來獲得簡單授權令牌模塊。我的認證部分很容易工作。我可以將憑據發送到身份驗證端點,並獲取令牌。但後來當我嘗試通過JSONAPIAdapter實現授權,我收到以下錯誤Ember無法使用ember-simple-auth和ember-simple-auth-token創建'authorizer:token'的實例

Error: Failed to create an instance of 'authorizer:token'. Most likely an improperly defined class or an invalid module export.

我使用灰燼2.12並具有以下設置:

應用程序/適配器/ application.js中

export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { 
    host: 'http://localhost:8000', 
    authorizer: 'authorizer:token' 
}); 

應用程序/路由/ users.js

import Ember from 'ember'; 

export default Ember.Route.extend({ 
    session: Ember.inject.service('session'), 
    model() { 
    return this.store.findAll('user'); 
    } 
}); 

的package.json

"ember-cli-simple-auth": "^0.8.0", 
"ember-simple-auth": "^1.2.2", 
"ember-simple-auth-token": "^2.1.0", 

回答

0

我不知道怎麼是你的鑑定者,但你可以嘗試這樣的事情你的授權:

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

export default Base.extend({ 
    session: Ember.inject.service(), 

    authorize(data, block) { 
    if (Ember.testing) { 
     block('Authorization', 'Bearer beyonce'); 
    } 
    const { token } = data 
    if (this.get('session.isAuthenticated') && token) { 
     block('Authorization', `Bearer ${token}`); 
    } 
    } 
});