2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2017-10-13 22:17:51 +00:00
|
|
|
import { default as ApplicationAdapter, namespace } from './application';
|
2021-04-01 18:21:30 +00:00
|
|
|
import OTTExchangeError from '../utils/ott-exchange-error';
|
2017-10-13 22:17:51 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
export default class TokenAdapter extends ApplicationAdapter {
|
2020-06-10 13:49:16 +00:00
|
|
|
@service store;
|
2017-10-14 19:42:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
namespace = namespace + '/acl';
|
2017-10-14 19:42:14 +00:00
|
|
|
|
|
|
|
findSelf() {
|
2021-12-28 14:45:20 +00:00
|
|
|
return this.ajax(`${this.buildURL()}/token/self`, 'GET').then((token) => {
|
2019-03-26 07:46:44 +00:00
|
|
|
const store = this.store;
|
2017-10-14 19:42:14 +00:00
|
|
|
store.pushPayload('token', {
|
|
|
|
tokens: [token],
|
|
|
|
});
|
|
|
|
|
|
|
|
return store.peekRecord('token', store.normalize('token', token).data.id);
|
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2021-04-01 18:21:30 +00:00
|
|
|
|
|
|
|
exchangeOneTimeToken(oneTimeToken) {
|
|
|
|
return this.ajax(`${this.buildURL()}/token/onetime/exchange`, 'POST', {
|
|
|
|
data: {
|
|
|
|
OneTimeSecretID: oneTimeToken,
|
|
|
|
},
|
2021-12-28 14:45:20 +00:00
|
|
|
})
|
|
|
|
.then(({ Token: token }) => {
|
|
|
|
const store = this.store;
|
|
|
|
store.pushPayload('token', {
|
|
|
|
tokens: [token],
|
|
|
|
});
|
2021-04-01 18:21:30 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
return store.peekRecord(
|
|
|
|
'token',
|
|
|
|
store.normalize('token', token).data.id
|
|
|
|
);
|
2021-12-28 14:45:20 +00:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
throw new OTTExchangeError();
|
|
|
|
});
|
2021-04-01 18:21:30 +00:00
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|