[Fixed]-Django rest + ember simple auth The authenticator “authenticator:oauth2” rejected to restore the session – invalidating

1👍

TLDR : Ember Social API Looks for access_token while DRF send out token

Server-Side Fix

You need to subclass TokenSerializer and override keyword = Bearer

Client Side Fix

The OAuth2Bearer expects a token value called access_token, and if this value exists it will add the Authorization header with a Bearer prefix.
However DRF Token expects the Authorization header to be prefixed with Token, see code below to better under stand

Working Authorizer for DRF TOKEN

import Ember from 'ember';
import Base from 'ember-simple-auth/authorizers/base';

const { isEmpty } = Ember;

export default Base.extend({
authorize(data, block) {
    const accessToken = data['token'];

    if (!isEmpty(accessToken)) {
      block('Authorization', `Token ${accessToken}`);
    }
  }
});

Reference to orignal OAuth2Bearer

Ember Social Auth – OAuth2Bearer

Leave a comment