0

I am so frustrated , i can't figure it out why ember-simple-auth does not persist when the page refresh's... I'm returning the access_token and i follow the docs to implement oauth2....

That's my code:

authenticators/oauth2.js:

import OAuth2PasswordGrant from 'ember-simple-auth/authenticators/oauth2-password-grant';

export default OAuth2PasswordGrant.extend({
  serverTokenEndpoint: 'http://localhost:3000/users/compare'
});

authorizers/oauth2.js:

import OAuth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer';

export default OAuth2Bearer.extend();

adapters/application.js:

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

const {
  JSONAPIAdapter
} = DS;

export default JSONAPIAdapter.extend(DataAdapterMixin, {
  authorizer: 'authorizer:oauth2',
  host: 'http://localhost:3000'
});

I'm returning the access_token and username. I'm able to see authenticated routes, but if i refresh the page, the session will be lost.

In my authenticated object i have:

access_token: "token"
username: "myUserName"

And in my secure object i have:

authenticator: "simple-auth-authenticator:jwt"
access_token "token"
username: "myUserName"

I can't figure it out why this authenticator.. I was using it but i already delete everything related.

In my localStorage i have:

{"secure":{"authenticator":"simple-auth-authenticator:jwt","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Im1hcmNlbG9AcHViY3Jhd2xzcC5jb20iLCJpYXQiOjE0NDk1OTY5NDV9.fP11KL2as2mI7ocFojS-H3jUW60XgWCUskTNi4iy1XY","name":"Fatima Alves"},"authenticated":{"authenticator":"authenticator:oauth2","access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Im1hcmNlbG9AcHViY3Jhd2xzcC5jb20iLCJpYXQiOjE0NTAzMDU3MDN9.GKb5A15BBXxgcO9SDrGnxv0CQvkhXQCqvrK65MQ2ROc","name":"Fatima Alves"}}

1 Answers1

0

You're missing some properties in the secure data which are required for the OAuth2PasswordGrantAuthenticator to restore correctly.

Check out the restore() implementation here.

uberclops
  • 161
  • 5
  • Ok, i was able to finally make it work, but i can't verify my token in every request because of this "Bearer". Should i take this off usando slice?? –  Dec 17 '15 at 09:50
  • I'm not sure what you are using server side, but if you're doing the auth yourself then feel free to strip it off. It's just there to indicate what type of token it is. – uberclops Dec 17 '15 at 10:02
  • I'm only using JWT and bcrypt @uberclops. –  Dec 17 '15 at 12:39
  • I'm using the same in a project, so yea just strip out `Bearer ` from the `Authorization` header in your auth layer on your server before validating the token. – uberclops Dec 17 '15 at 12:57
  • JWT could have some help to do that. –  Dec 17 '15 at 13:28