1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { MicrosoftAppCredentials } from './auth/microsoftAppCredentials';
|
9 |
|
10 | export class EmulatorApiClient {
|
11 | public static async emulateOAuthCards(credentials: MicrosoftAppCredentials, emulatorUrl: string, emulate: boolean): Promise<boolean> {
|
12 | let token = await credentials.getToken();
|
13 | let requestUrl: string = emulatorUrl + (emulatorUrl.endsWith('/') ? '' : '/') + `api/usertoken/emulateOAuthCards?emulate=${ (!!emulate).toString() }`;
|
14 |
|
15 | const res = await fetch(requestUrl, {
|
16 | method: 'POST',
|
17 | headers: {
|
18 | Authorization: `Bearer ${ token }`
|
19 | }
|
20 | });
|
21 |
|
22 | if (res.ok) {
|
23 | return true;
|
24 | } else {
|
25 | throw new Error(`EmulateOAuthCards failed with status code: ${ res.status }`);
|
26 | }
|
27 | }
|
28 | }
|
29 |
|