# Automatically authorize Ember Data requests

**URL:** <https://discuss.emberjs.com/t/automatically-authorize-ember-data-requests/16728>\
**Category:** General\
**Created:** [June 29, 2019, 10:06pm UTC](https://discuss.emberjs.com/t/automatically-authorize-ember-data-requests/16728 "2019-06-29T22:06:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwerty](https://avatars.discourse-cdn.com/v4/letter/q/4491bb/32.png) [@qwerty](https://discuss.emberjs.com/u/qwerty)\
**Post date:** [June 29, 2019, 10:06pm UTC](https://discuss.emberjs.com/t/automatically-authorize-ember-data-requests/16728/1 "2019-06-29T22:06:27Z")

</div>

Hi, I use ember-simple-auth-token extension. I can authenticate but when I try get ember data by

`this.store.findAll('post')`

the request is without Authorization with Bearer + token.

Can someone show me what I do wrong?

My setup:

```
ember - octane
ember-cli: 3.9.0
node: 10.15.3
"ember-data": "github:emberjs/data#1df833396855d956b817540923dd89338463fec2",
"ember-simple-auth-token": "^4.0.7",

```

> app/adapters/application.js

```
import DS from 'ember-data';
import TokenAuthorizerMixin from 'ember-simple-auth-token/mixins/token-authorizer';

const { JSONAPIAdapter } = DS;

export default class ApplicationAdapter extends JSONAPIAdapter.extend(TokenAuthorizerMixin) {
    host = 'http://api.myproject.local';
    namespace = 'v1';
}

```

> app/initializers/application.js

```
import Inflector from 'ember-inflector';

export function initialize(/* application */) {
  // application.inject('route', 'foo', 'service:foo');

  const inflector = Inflector.inflector;

  inflector.uncountable('post');
}

export default {
  initialize
};

```

> app/models/post.js

```
import DS from 'ember-data';
const { Model, attr } = DS;

export default class PostModel extends Model {
  @attr('number') id;
  @attr('string') title;
}

```

> app/routes/application.js

```
import Route from '@ember/routing/route';

import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default class ApplicationRoute extends Route.extend(ApplicationRouteMixin) {

}

```

> app/routes/index.js

```
import Route from '@ember/routing/route';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import { inject as service } from '@ember/service';

export default class IndexRoute extends Route.extend(AuthenticatedRouteMixin) {
    @service store;
    @service session;

    model() {
        return this.store.findAll('post');
    }
}

```

> app/serializers/application.js

```
import DS from 'ember-data';

export default class ApplicationSerializer extends DS.JSONSerializer {

}

```

> app/session-stores/application.js

```
import CookieStore from 'ember-simple-auth/session-stores/cookie';

export default CookieStore.extend();

```

> app/routes.js

```
import EmberRouter from "@ember/routing/router";
import config from "./config/environment";

const Router = EmberRouter.extend({
  location: config.locationType,
  rootURL: config.rootURL
});

Router.map(function() {
  this.route('login');
});

export default Router;

```

> app/config/environment.js

```
  ENV['ember-simple-auth'] = {
    authorizer: 'authorizer:token'
  };

  ENV['ember-simple-auth-token'] = {
    refreshAccessTokens: true,
    refreshLeeway: 300, // refresh 5 minutes (300 seconds) before expiration
    serverTokenEndpoint: 'http://api.myproject.local/v1/user/login', // Server endpoint to send authenticate request
    tokenPropertyName: 'token', // Key in server response that contains the access token
    // headers: {} // Headers to add to the
  };

```

Thanks for help.

---

<div class="post-metadata">

**Author:** ![qwerty](https://avatars.discourse-cdn.com/v4/letter/q/4491bb/32.png) [@qwerty](https://discuss.emberjs.com/u/qwerty)\
**Post date:** [June 30, 2019, 5:49am UTC](https://discuss.emberjs.com/t/automatically-authorize-ember-data-requests/16728/2 "2019-06-30T05:49:41Z")

</div>

I tried the same setup in 3.10 version and everything works fine.

What can I do to fix auth in Octane?

I noticed that authorize(xhr) method not call from TokenAuthorizerMixin in Octane.

---

<div class="post-metadata">

**Author:** ![AdmiralBolt](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/admiralbolt/32/16753_2.png) [@AdmiralBolt](https://discuss.emberjs.com/u/AdmiralBolt)\
**Post date:** [October 20, 2019, 11:54pm UTC](https://discuss.emberjs.com/t/automatically-authorize-ember-data-requests/16728/3 "2019-10-20T23:54:49Z")

</div>

I was running into the same issues as you, I think it has to do with the deprecation of authorizers see: [GitHub - simplabs/ember-simple-auth: A library for implementing authentication/authorization in Ember.js applications.](https://github.com/simplabs/ember-simple-auth#deprecation-of-authorizers). Following the example provided and computing the headers instead of using the TokenAuthorizerMixin solved my problem!
