2
votes

i am using Ember CLI + Ember Data + Simple Auth. The authenticator is working fine. But when im am doing a Rest Call with Ember Data Rest Adapter this.store.findAll("user"); the authorize function in my custom authorizer don't gets called.

The Rest API Endpoint is on an other domain, so i added the url to the crossOriginWhitelist in my environment.js.

environment.js:

module.exports = function(environment) {
    var ENV = {
        // some configuration
    };

    ENV['simple-auth'] = {
        crossOriginWhitelist: ['http://api.xxxx.com'],
        authorizer: 'authorizer:xxxx',
        routeAfterAuthentication: 'dashboard',
    };

    return ENV;
};

authorizer

import Ember from 'ember';
import Base from 'simple-auth/authorizers/base';

var XXXXAuthorizer = Base.extend({
    authorize: function(jqXHR, requestOptions) {
        // Some Code, gets not called, damn it :(
    }
});



export default {
    name: 'authorization',
    before: 'simple-auth',
    initialize: function(container) {
        container.register('authorizer:xxxx', XXXXAuthorizer);
    }
};

index.html

....
        <script>
            window.XXXXWebclientENV = {{ENV}};
            window.ENV = window.MyAppENV;
            window.EmberENV = window.XXXXWebclientENV.EmberENV;
        </script>
        <script>
            window.XXXXWebclient = require('xxxx-webclient/app')['default'].create(XXXXWebclientENV.APP);
        </script>
....

Thanks for help :)

2

2 Answers

1
votes

I had a similar problem. For me it was the crossOriginWhitelist config.

I set it like this:

// config/environment.js

ENV['simple-auth'] = {
  crossOriginWhitelist: ['*']   // <-- Make sure it's an array, not a string
};

to see if I could get it working (I could), then I could narrow it down to figure out exactly what URL I should use to enforce the restriction (port number and hostname etc).

Don't leave it like that though!

You should actually figure out what URL works for the whitelist, and use that.

0
votes

I am facing the same issue. I have same setup but the authorize function is not being called. May be you can try by adding the port number in your crossOriginWhiteList url.

I am adding window.ENV = window.MyAppENV line in new initializer which runs before simple-auth. You have added that in index file and may be that is the reason why simple-auth is not able to read your configuration.

Does the other configuration routeAfterAuthentication: 'dashboard', works properly? If not then this might be the reason. Try adding new initializer like

  export default {
  name: 'simple-auth-config',
  before: 'simple-auth',

    initialize: function() {
        window.ENV = window.MyAppNameENV;
    }    
 };