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.

4

1 回答 1

0

这里的问题是相当愚蠢的:我的大小写crossOriginWhitelist不正确。

于 2014-10-16T21:58:52.023 回答