0

I'm trying to implement a custom authorizer (using ember-cli and ember-cli-simple-auth) but the authorize method is not being called on any requests. The init function is being called and the message that appears in the console when there is no authorizer registered is no longer showing up. Here is the initializer code:

import Ember from 'ember';
import Base from 'simple-auth/authorizers/base';
import ENV from '../config/environment';

ENV['simple-auth'] = ENV['simple-auth'] || {};
ENV['simple-auth'].authorizer = 'authorizer:custom';
ENV['simple-auth'].crossOriginWhiteList = [ENV.NET.API_ENDPOINT];

var CustomAuthorizer = Base.extend({
    init: function () {
        console.log('Intialize authorizer');
    },
    authorize: function(jqXHR, requestOptions) {
        console.log('Authorize');
        var token = this.get('session.token');
        if(this.get('session.isAuthenticated') && !Ember.isEmpty(token)) {
            authValue = "Token " + token;
            jqXHR.setRequestHeader('Authorization', authValue);
        }
    }
});

export default {
    name: 'authorization',
    before: 'simple-auth',
    initialize: function(container, application) {
        console.log('Registered');
        container.register('authorizer:custom', CustomAuthorizer);
    }
};

Any help would be appreciated.

Alex
  • 463
  • 3
  • 12

1 Answers1

0

Problem here was something quite dumb: my casing of crossOriginWhitelist was incorrect.

Alex
  • 463
  • 3
  • 12
  • Hi Alex, are you sure it was because of that? I have the same problem but no way... – masciugo Nov 06 '14 at 16:37
  • @masciugo Yeah, fortunately, it was a simple capital L that was causing the issues. If you'd like to start a new question and link to it I'll take a look. – Alex Nov 07 '14 at 18:19
  • [Solved](http://stackoverflow.com/a/26803347/626341), thanks. So hard to debug JS apps.. – masciugo Nov 10 '14 at 09:56