diff --git a/app/authorizers/application.js b/app/authorizers/application.js new file mode 100644 index 0000000..68755e3 --- /dev/null +++ b/app/authorizers/application.js @@ -0,0 +1,3 @@ +import OAuth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer'; + +export default OAuth2Bearer.extend({}); diff --git a/app/pods/application/adapter.js b/app/pods/application/adapter.js index 11498d0..96daa1a 100644 --- a/app/pods/application/adapter.js +++ b/app/pods/application/adapter.js @@ -1,6 +1,9 @@ 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() { return 'api/' + this.get('globals.genus'); }.property(), diff --git a/app/services/session-account.js b/app/services/session-account.js new file mode 100644 index 0000000..1b34554 --- /dev/null +++ b/app/services/session-account.js @@ -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), + }); + } + }) +});