Skip to content

Instantly share code, notes, and snippets.

@jrhe
Created June 6, 2014 18:45
Show Gist options
  • Save jrhe/86df5a03d2f88c1b6ac3 to your computer and use it in GitHub Desktop.
Save jrhe/86df5a03d2f88c1b6ac3 to your computer and use it in GitHub Desktop.
Ember.SimpleAuth.Authenticators.OAuth2.reopen({
serverTokenEndpoint: ENV.api.host + '/' + ENV.api.namespace + '/oauth/token',
restore: function(properties) {
return new Ember.RSVP.Promise(function(resolve, reject) {
if (!Ember.isEmpty(properties.user_token) &&
!Ember.isEmpty(properties.user_email) &&
!Ember.isEmpty(properties.resource_owner_id)) {
resolve(properties);
} else {
reject();
}
});
},
});
export default {
name: 'authentication',
initialize: function(container, application) {
// customize the session so that it allows access to the account object
Ember.SimpleAuth.Session.reopen({
user: function() {
var userId = this.get('resource_owner_id');
if (!Ember.isEmpty(userId)) {
return container.lookup('store:main').find('user', userId);
}
}.property('resource_owner_id')
});
Ember.SimpleAuth.setup(container, application, {
authorizerFactory: 'ember-simple-auth-authorizer:oauth2-bearer'
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment