frontend/js/common/auth/fetch_token.js
Paulus Schoutsen 3b7a206cec
Add an authorize page for authentication (#1147)
* Use authorize page if auth provider

* Add webcomponent polyfill

* More fixes

* ES5 fix

* Lint

* Use redirect_uri

* upgrade uglify to fix tests?

* Update browsers used for testing
2018-05-10 14:25:36 -04:00

16 lines
416 B
JavaScript

export default function fetchToken(clientId, code) {
const data = new FormData();
data.append('grant_type', 'authorization_code');
data.append('code', code);
return fetch('/auth/token', {
method: 'POST',
headers: {
authorization: `Basic ${btoa(clientId)}`
},
body: data,
}).then((resp) => {
if (!resp.ok) throw new Error('Unable to fetch tokens');
return resp.json();
});
}