Hi I am trying to write my own Authorizer using ember simple auth. However Ember-cli doesn't see to be picking it up and it is still saying No authorizer was configured for Ember Simple Auth - specify one if backend requests need to be authorized.
I am using ember-cli 0.1.1
Here is my initializer:
var CustomAuthorizer = SimpleAuth.Authorizers.Base.extend({
authorize: function(jqXHR, requestOptions){
console.log('authCCC', jqXHR, requestOptions);
}
});
export default {
name: 'authorization',
before: 'simple-auth',
initialize: function(container, application) {
container.register('authorizer:custom', CustomAuthorizer);
}
};
Then according to the doc i need to do this in my config/environment.js
ENV['simple-auth'] = {
authorizer: 'authorizer:custom'
};
Not sure what is wrong here. From the author all i get is a link to the doc which doesn't help :/
Thanks in advance.
EDIT
Here is my full environment.js
module.exports = function(environment) {
var ENV = {
modulePrefix: 'app-client',
environment: environment,
baseURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
contentSecurityPolicy: {
'font-src': "'self' https://fonts.gstatic.com"
}
};
ENV['simple-auth'] = {
authorizer: 'authorizer:custom'
};
if (environment === 'development') {
ENV.APP.LOG_RESOLVER = true;
ENV.APP.LOG_ACTIVE_GENERATION = true;
ENV.APP.LOG_VIEW_LOOKUPS = true;
ENV.APP.SERVER_URL = 'http://localhost:3000';
// ENV.APP.SERVER_URL = 'http://0.0.0.0:3000';
}
if (environment === 'test') {
// Testem prefers this...
ENV.baseURL = '/';
ENV.locationType = 'auto';
// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
}
if (environment === 'staging') {
ENV.APP.SERVER_URL = 'http://apistaging.server.io';
}
if (environment === 'production') {
ENV.APP.SERVER_URL = 'https://api.server.io';
}
return ENV;
};
authorize
method is called for every XHR request (unless it's a cross origin request and the origin has not beed whitelisted) - check the docs here: github.com/simplabs/ember-simple-auth#authorizers. – marcoow