Setup authorizer and custom session for account

This commit is contained in:
Matthew Ryan Dillon 2015-10-20 15:04:14 -07:00
parent 30b1706868
commit 52979ac9e2
3 changed files with 29 additions and 1 deletions

View file

@ -0,0 +1,3 @@
import OAuth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer';
export default OAuth2Bearer.extend({});

View file

@ -1,6 +1,9 @@
import DS from 'ember-data'; import DS from 'ember-data';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
export default DS.RESTAdapter.extend(DataAdapterMixin, {
authorizer: 'authorizer:application',
export default DS.RESTAdapter.extend({
namespace: function() { namespace: function() {
return 'api/' + this.get('globals.genus'); return 'api/' + this.get('globals.genus');
}.property(), }.property(),

View file

@ -0,0 +1,22 @@
import Ember from 'ember';
import DS from 'ember-data';
import parseBase64 from '../utils/parse-base64';
const { service } = Ember.inject;
export default Ember.Service.extend({
session: service('session'),
store: service(),
account: Ember.computed('session.data.authenticated.access_token', function() {
const token = this.get('session.data.authenticated.access_token');
const claims = parseBase64(token);
const id = claims['sub'];
if (!Ember.isEmpty(id)) {
return DS.PromiseObject.create({
promise: this.get('store').findRecord('user', id),
});
}
})
});