deviseember-cliember-simple-auth

Ember-cli-simple-auth-devise :Authorization: Token token="<user_token>", user_email="<user_email>" (Header not added)


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 
  }
});

Solution

  • 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'
    };