UNPKG

940 BPlain TextView Raw
1/**
2 * @module botbuilder
3 */
4/**
5 * Copyright (c) Microsoft Corporation. All rights reserved.
6 * Licensed under the MIT License.
7 */
8import { MicrosoftAppCredentials } from './auth/microsoftAppCredentials';
9
10export 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