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

This mixin can be used to make Ember Data adapters authorize all outgoing API requests by injecting a header. It works with all authorizers that call the authorization callback (see authorize) with header name and header content arguments.

The DataAdapterMixin will also invalidate the session whenever it receives a 401 response for an API request.

// app/adapters/application.js
          import DS from 'ember-data';
          import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
          
          export default DS.JSONAPIAdapter.extend(DataAdapterMixin, {
            authorizer: 'authorizer:application'
          });
          

The DataAdapterMixin requires Ember Data 1.13 or later.

Methods

source protected

ajaxOptions( )

Defines a beforeSend hook (see http://api.jquery.com/jQuery.ajax/) that injects a request header containing the authorization data as constructed by the authorizer (see authorize). The specific header name and contents depend on the actual authorizer that is used.

This method applies for Ember Data 2.6 and older. See headersForRequest for newer versions of Ember Data.

source protected

handleResponse(status)

This method is called for every response that the adapter receives from the API. If the response has a 401 status code it invalidates the session (see invalidate).

Arguments

status: Number

The response status as received from the API

source protected

headersForRequest( )

Adds request headers containing the authorization data as constructed by the authorizer.

This method will only be called in Ember Data 2.7 or greater. Older versions will rely on ajaxOptions for request header injection.

Properties

source public

authorizer: String

Default: null

The authorizer that is used to authorize API requests. The authorizer has to call the authorization callback (see authorize) with header name and header content arguments. This property must be overridden in adapters using this mixin.

source public readonly

session: SessionService

The session service.

Extends

Ember.Mixin

Properties