-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.js
42 lines (36 loc) · 1.09 KB
/
fetch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Makes a GET request using authorization header. For more, visit:
* https://tools.ietf.org/html/rfc6750
* @param {string} accessToken
* @param {string} apiEndpoint
*/
export const callApiWithToken = async(accessToken, apiEndpoint) => {
const headers = new Headers();
const bearer = `Bearer ${accessToken}`;
headers.append("Authorization", bearer);
const options = {
method: "GET",
headers: headers
};
return fetch(apiEndpoint, options)
.then(response => response.json())
.catch(error => console.log(error));
}
/**
* Makes a POST request sending token.
* @param {string} accessToken
* @param {string} apiEndpoint
*/
export const callOwnApiWithToken = async(accessToken, apiEndpoint) => {
return fetch(apiEndpoint, {
method: "POST",
body: JSON.stringify({
ssoToken: accessToken
})
}).then(response => response.json())
.catch(error => console.log(error));
}