Search code examples
jsonnode.jssessionember.jsember-simple-auth

How to access Ember-Simple-Auth-Token authorizer header in NodeJS endpoint


I am trying to figure out where the authorizer:application' gets set in the request. Should it be somewhere in the headers? I am unable to find it in the request in the nodejs endpoint when making requests from the app.

The code I have in ember (adapter/application.js) is:

import DS from "ember-data";
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';

export default DS.RESTAdapter.extend(DataAdapterMixin, {
  authorizer: 'authorizer:application',

And the endpoint is a simple:

exports.getAuthorizer = function(req, res) {
  console.log(req);
}

I have logged req hoping I can find the authorizer inside but can't find it.

If you require more information please let me know, thanks

ember-simple-auth-token: https://github.com/jpadilla/ember-simple-auth-token


Solution

  • To access the authorizer token in the API I just needed to simply do the following:

    exports.getAuthorizer = function(req, res) {
      if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
        return req.headers.authorization.split(' ')[1];
      } else if (req.query && req.query.token) {
        return req.query.token;
      } else {
        return null;
      }
    }
    

    https://github.com/auth0/express-jwt

    The thing stopping me from doing this in the first place was that the header was never being sent. I had ember-cli-simple-auth as well as ember-simple-auth.

    The fix was to remove ember-cli-simple-auth and ember-cli-simple-auth-token from the project (https://github.com/jpadilla/ember-simple-auth-token/issues/96)