Reputation: 2468
So I realize that the account example here: https://github.com/simplabs/ember-simple-auth/blob/8863c032fcea6148a5b3365be5d66dc2389d301d/examples/4-authenticated-account.html
Provides the code for retrieving the currently logged in account. I just have a few questions about the example as I am trying to get it working in an Ember-CLI app.
SimpleAuth
is being used in the example however, I don't know where it's coming from as I am trying to import SimpleAuth from ...
but I don't know what file to import it from.
Furthermore, I am wondering if the response from the server now needs to return the user_id as well with the access_token/refresh_token?
If so, is that oauth compatible?
EDIT: My current code
// app/initializers/oauth-custom.js
import Ember from 'ember';
import OAuthCustomAuthenticator from 'front/authenticators/oauth-custom';
import Session from 'simple-auth/session';
export default {
name: 'oauth-custom',
before: 'simple-auth',
initialize: function(container) {
Session.reopen({
currentUser: function() {
var user_id = this.get('user_id');
if (!Ember.isEmpty(user_id)) {
return container.lookup('store:main').find('user', user_id);
}
}.property('user_id')
});
container.register(
'oauth-custom:oauth2-password-grant',
OAuthCustomAuthenticator
);
}
};
Authentication works out perfectly, it's just that I don't see any call /user/id that ember tries to make.
Sample response from the server:
{
"access_token": "asdf",
"token_type": "bearer",
"expires": 1406082157,
"expires_in": 604800,
"refresh_token": "asdf",
"user_id": "1"
}
Upvotes: 1
Views: 1444
Reputation: 4062
The SimpleAuth global is only defined in the browserified distribution of the library. When you're using ember-cli you import the individual components instead of accessing them via the global (see e.g. this example: http://log.simplabs.com/post/90339547725/using-ember-simple-auth-with-ember-cli).
To e.g. get the session you'd do sty like:
import Session from 'simple-auth/session';
Session.reopen({
…
});
The example linked above requires the server to include the user_id
in the response which is not compliant with the OAuth 2.0 specification but a customization. If you want/need to be compliant you could get the current user e.g. via a GET /me
or sth. like that once the session is authenticated.
Upvotes: 3