【发布时间】:2014-04-15 15:02:04
【问题描述】:
我正在尝试在 Node.js 服务器上运行的 Ember 应用上设置授权。
我正在使用 oauth2 Authenticator,它正在从服务器请求令牌。这工作正常。我能够为应用程序提供一个令牌,它保存在本地存储中。
但是,当我发出后续请求时,授权方并未将令牌添加到标头中,我已使用文档中描述的方法(http://ember-simple-auth.simplabs.com/ember-simple-auth-oauth2-api-docs.html)初始化了授权方:
Ember.Application.initializer({
name: 'authentication',
initialize: function(container, application) {
Ember.SimpleAuth.setup(container, application, {
authorizerFactory: 'authorizer:oauth2-bearer'
});
}
});
var App = Ember.Application.create();
并且我已经向 Authorizer 添加了一个 init 方法,用于在初始化时向服务器记录一条消息,因此我知道它正在被加载。唯一的问题是,授权方的授权方法永远不会被调用。
感觉好像我错过了图书馆的基本概念。
我有一条使用 AuthenticatedRouteMixin 保护的用户路由,如下所示:
App.UsersRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, {
model: function() {
return this.get('store').find('user');
}
});
如果会话中没有令牌,则它正在获取数据,很好,并重定向到 /login,但请求标头不包含令牌:
GET /users HTTP/1.1
Host: *****
Connection: keep-alive
Cache-Control: no-cache
Pragma: no-cache
Accept: application/json, text/javascript, */*; q=0.01
Origin: *****
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Referer: *****
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
您能给我的任何帮助将不胜感激。
【问题讨论】:
标签: authentication ember.js oauth