2014-07-03 24 views
1

做Ember.SimpleAuth.setup使用燼,簡單AUTH使用燼-CLI-簡單AUTH我有這個初始化之前:如何通過AMD

Ember.Application.initializer({ 
    name: 'authentication', 
    initialize: function(container, application) { 
    container.register('authenticator:api', Oauth2Authenticator); 

    Ember.SimpleAuth.setup(container, application, { 
     authorizerFactory: 'ember-simple-auth-authorizer:oauth2-bearer', 
     routeAfterAuthentication: 'dashboard', 
     routeAfterInvalidation: 'login', 
     storeFactory: 'ember-simple-auth-session-store:local-storage' 
    }); 
    } 
}); 

如何做到這一點,現在,使用進口的時候,我設法解決了這個問題:

import Oauth2Authenticator from '../services/authenticator'; 

export default { 
    name: 'authentication', 
    initialize: function(container, app) { 
    container.register('authenticator:api', Oauth2Authenticator); 

    // THIS PART IS NOT CLEAR, HOW TO SETUP IN AMD? 
    Ember.SimpleAuth.setup(container, application, { 
     authorizerFactory: 'ember-simple-auth-authorizer:oauth2-bearer', 
     routeAfterAuthentication: 'dashboard', 
     routeAfterInvalidation: 'login', 
     storeFactory: 'ember-simple-auth-session-store:local-storage' 
    }); 
    // END OF CONFUSING PART 
    } 
}; 

謝謝!

回答

3

因爲現在是私人API,所以不能再打SimpleAuth.setup了。如果您使用Ember CLI,只需安裝Ember CLI插件:https://github.com/simplabs/ember-cli-simple-auth。如果您使用EAK(在這種情況下,你應該遷移到灰燼CLI反正),請確保您所需要的灰燼簡單驗證自動加載磁帶機:

require('simple-auth/ember');

而且籤自述安裝說明:https://github.com/simplabs/ember-simple-auth#installation

在這兩種情況下,您不必撥打SimpleAuth.setup。如果你想註冊您的自定義驗證器,只需將「簡單-auth的」初始化之前添加運行一個初始化:

import Oauth2Authenticator from '../services/authenticator'; 

export default { 
    name: 'authentication', 
    before: 'simple-auth', 
    initialize: function(container, app) { 
    container.register('authenticator:api', Oauth2Authenticator); 
    } 
}; 

配置現在通過全球ENV對象來完成 - 見API文檔在這裏:http://ember-simple-auth.simplabs.com/ember-simple-auth-api-docs.html#SimpleAuth-Configuration