简体   繁体   English

ember-simple-auth oauth2授权者问题

[英]ember-simple-auth oauth2 authorizer issue

I am trying to set up authorization on an Ember App running on a Node.js server. 我正在尝试在Node.js服务器上运行的Ember App上设置授权。

I am using the oauth2 Authenticator, which is requesting a token from the server. 我正在使用oauth2 Authenticator,它正在从服务器请求令牌。 This is working fine. 一切正常。 I am able to provide the app with a token, which it saves in the local-storage. 我可以为应用提供令牌,并将其保存在本地存储中。

However, when I make subsequent requests, the authorizer is not adding the token to the header, I have initialized the authorizer using the method described in the documentation ( http://ember-simple-auth.simplabs.com/ember-simple-auth-oauth2-api-docs.html ): 但是,当我发出后续请求时,授权者未将令牌添加到标头中,而是使用文档( 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();

And I have added an init method to the Authorizer, to log a message to the server when it is initialized, so I know that it is being loaded. 并且我在授权程序中添加了一个init方法,以便在初始化消息时将消息记录到服务器,因此我知道该消息正在加载。 The only thing is, the authorize method of the authorizer is never called. 唯一的事情是,永远不会调用授权者的authorize方法。

It feels like I am missing a fundamental concept of the library. 感觉上好像我缺少图书馆的基本概念。

I have a users route which I have protected using the AuthenticatedRouteMixin like so: 我有一个使用AuthenticatedRouteMixin保护的用户路由,如下所示:

App.UsersRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, {
  model: function() {
    return this.get('store').find('user');
  }
});

Which is fetching the data, fine, and redirects to /login if no token is in the session, but the request headers do not include the token: 如果会话中没有令牌,则可以正常获取数据并重定向到/ 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

Any help you could give me would be greatly appreciated. 您能给我的任何帮助将不胜感激。

Is your REST API served on a different origin than the app is loaded from maybe? 您的REST API的来源是否不同于应用加载的来源? Ember.SimpleAuth does not authorizer cross origin requests by default (see here: https://github.com/simplabs/ember-simple-auth#cross-origin-authorization ) 默认情况下,Ember.SimpleAuth不会授权跨源请求(请参阅此处: https : //github.com/simplabs/ember-simple-auth#cross-origin-authorization

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM