Ember data django rest adapter authorization jwt


#1

HI everyone, i’m using ember-simple-auth and ember-simple-auth-token to implement a client side session mechanism. My backend is writtend in django(DRF + DRF jwt) and I’m using ember-django-adapter. I defined a route users, a model user but when i try to go to http://myhost/users i have this error:

Error while processing route: users.index Authentication credentials were not provided. Error: Authentication credentials were not provided.

How can i tell to ember django adapter to add a specific authorization token(grabbed from ember-simpe-auth session) when making an http request?

Thank You.


#2

Hi @cresg820,

I use ember-simple-auth with my DRF projects as well, although I’m using the oauth2 flavor. ember-django-adapter should not interfere with any extra headers added by the token authorizer.

Did you configure the authorizer correctly?

e.g.:

// config/environment.js
ENV['simple-auth'] = {
  authorizer: 'simple-auth-authorizer:token'
};

#3

HI @dustinfarris, i’m using ember-cli and i added to config\environment.js this code

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

ENV['simple-auth-token'] = {
  serverTokenEndpoint: 'http://myhost/api/jwt-auth/',
  identificationField: 'username',
  tokenPropertyName: 'token',
  authorizationPrefix: 'JWT',
  authorizationHeaderName: 'Authorization',
};

When I check under Resources -> Local Storage(under chrome debug console) I see a key ember_simple_authsession with this value: {“authenticator”:“simple-auth-authenticator:token”,“token”:“xxxxxxxxxx”}.

And if i check under Network -> Users -> Headers(under chrome debug console) in Request Headers there is no trace about authorization header.


#4

I did not read this in ember-simple-auth docs https://github.com/simplabs/ember-simple-auth/tree/master/packages/ember-simple-auth#cross-origin-authorization and I didn’t add my backend to crossOriginWhilelist


#5

Aha! Well there you go. Glad it was a simple fix.