0

The 'Authorization' header is not being set for some reason. I have tried setting the authorizer in config/environment.js with

updated:as per @marcoow suggestion

 ENV['simple-auth'] = {
    crossOriginWhitelist: ['*'],
    authorizer: 'simple-auth-authorizer:devise'
  };
  ENV['simple-auth-devise'] = {
    serverTokenEndpoint: 'users/sign_in',
  };

...I am able to login to my application by for updating other resources like post Authorization: Token token="", user_email="" is not getting added to my sever call

controller/dashboard.js

import Ember from 'ember';
export
default Ember.Controller.extend({
    actions: {
        add: function () {
            var name = this.get('name');
            var start = this.get('Start');
            var end = this.get('End');
            var game = this.store.createRecord('game', {
                name: name,
                start: start,
                end: end
            });
            game.save();
        }
    }
});

my request looks something like this

**1. MY under standing is that the request headers here should contain Authorization: header too.

  1. I am using rack-cors gem to enable cors
  2. I looked into source of ember-simple-auth-devise / lib / simple-auth-devise / authorizers / devise.js. the authorize: function() add this to request. I am not sure how to call this method.

Request headers

login controller

import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export
default Ember.Controller.extend(LoginControllerMixin, {
    authenticator: 'simple-auth-authenticator:devise',
    actions: {
        authenticate: function () {
            console.log('i was called');
            var self = this;
            var data = this.getProperties('identification', 'password');
            self.get('session').authenticate(this.get('authenticator'), data).then(function () {
                self.transitionToRoute('dashboard');
            }, function (error) {
                console.log(error);
            });
        }
    }
});

I can see:

How can i authorize my Model#save with devise....using ember-data devise authorizer in controller

just for debugging i did this in route/dashboard.js

import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin,{
  model: function() {
    console.log(this.get('session.isAuthenticated')); # this is true 
  }
});
Cœur
  • 37,241
  • 25
  • 195
  • 267
Rigel
  • 882
  • 1
  • 11
  • 32
  • So, you are authenticating to server A, but you want to fetch resources from server B right? And the problem is that server B needs the same authentication as in server A, correct? – givanse Nov 10 '14 at 04:06
  • 1
    Hi my sessionController had issues and hence my user was not getting authentorized and Authorization: Token ...headers were not displayed in my call. just copy pasted the session controller from you github example and started working – Rigel Nov 11 '14 at 02:51

2 Answers2

1

crossOriginWhitelist is not a property of the Devise package - you need to configure that for the Ember Simple Auth base package:

ENV['simple-auth'] = {
  crossOriginWhitelist: ['*']
};

ENV['simple-auth-devise'] = {
  serverTokenEndpoint: 'users/sign_in',
  authorizer: 'authorizer:devise'
};
marcoow
  • 4,062
  • 1
  • 14
  • 21
  • thank you for the quick reply.but it is not still working Provisional headers are shown Accept:application/json, text/javascript, */*; q=0.01 Content-Type:application/json; charset=UTF-8 Origin:http://localhost:4200 Referer:http://localhost:4200/dashboard User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36 X-DevTools-Emulate-Network-Conditions-Client-Id:92FBA4BB-F997-4006-A262-EB014487ADE3 X-Requested-With:XMLHttpRequest – Rigel Nov 07 '14 at 17:53
  • Not sure what these headers are. When you're making CORS requests you have to make sure the server allows them as well - use rack-cors or a similar middleware. – marcoow Nov 08 '14 at 07:42
  • thanks @marcoow.I am using rack-cors to enable cors....i guess the authorize method in authorize/devise.js is not getting executed in my case. as i am able to login but i am not able to pass the user_email and user_token to server. may be there is lack of understanding from my side – Rigel Nov 08 '14 at 15:35
  • You'll have to debug into the code - specifically here: https://github.com/simplabs/ember-simple-auth/blob/master/packages/ember-simple-auth/lib/simple-auth/setup.js#L70 – marcoow Nov 10 '14 at 07:25
0

Have the same problem, my Authorization Header not added, too. My problem due to the response from Rails authenticate. In ember-simple-auth, I set identificationAttributeName to "username", but the json response from Rails authenticate("sessions#create" action) is like this: { token: 'xxxxx', user_email: 'xxxx' }, without a "username" field!

Solved by remove "user_email" field from session create action's response, add "username" field. Hope this will be helpful.