2015-04-30 88 views
0

我一直拉我的头发试图找出我错过了什么;我正在使用simple-authsimple-auth-token库(通过ember-cli 0.2.3),似乎无法让我的应用程序设置适当的Athentication: HTTP标头。从我读过的内容来看,最常见的疏漏是没有在simple-auth ENV变量上设置crossOriginWhitelist:属性。但是,即使值为['*'],我似乎也无法让Ember发送带有API请求的标头。请注意,我正在取代之前手卷(尽管是半熟!)auth解决方案,因此我知道我的API服务器可以正常工作,并且进行身份验证,并且凭借正确的凭据。Ember simple-auth-token将不会白名单API服务器

当我运行login行动时,一切都完美无瑕。如果我之后遇到受保护的Ember路线,它也可以正常工作。问题出现在Ember-data试图打我的API时(在http://localhost:3000);它得到一个401(因为它没有设置Authorization:标题)并转换到我的网站的索引。

这里的代码中的相关章节:

配置/ environments.js

... 

ENV['simple-auth'] = { 
    authenticationRoute: 'login', 
    authorizer: 'simple-auth-authorizer:token', 
    crossOriginWhitelist: ['*'] 
}; 
ENV['simple-auth-token'] = { 
    identificationField: 'email', 
    passwordField: 'password', 
    tokenPropertyName: 'token', 
    authorizationPrefix: 'Bearer ', 
    authorizationHeaderName: 'Authorization' 
}; 
... 

路线/ login.js

import Ember from 'ember'; 

export default Ember.Route.extend({ 
    actions: { 
    login: function(){ 
     var creds = this.controller.getProperties('identification', 'password'); 
     this.get('session').authenticate('simple-auth-authenticator:jwt', creds) 
     .then(function() { 
      // + 
      }, function() { 
      // - 
     }); 
    } 
    } 
}); 

路线/ application.js中

import Ember from 'ember'; 
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin'; 

export default Ember.Route.extend(ApplicationRouteMixin); 

在此先感谢。

回答

0

config/environment.js,尝试添加:

var ENV = { 
    ... 
    contentSecurityPolicy: { 
    'default-src': "'none'", 
    'script-src': "'self'", 
    'font-src': "'self'", 
    'connect-src': "'self' *", 
    'img-src': "'self'", 
    'style-src': "'self'", 
    'media-src': "'self'" 
    } 
    ... 
}; 
+0

没有骰子,可悲。难道我的服务器不是以正确格式的方式发回数据?它似乎正在将它存储在localstorage中,而且正如人们所期望的那样,该键被设置为'token“。 – jackweinbender

+0

那么,暂时我刚刚在我的适配器中直接引用了localStorage中的值,并在那里设置了头文件。 – jackweinbender

相关问题