diff --git a/samples/meetings-share-to-stage-signing/csharp/Source/MeetingSigning.Web/ClientApp/src/api/fetchClient.ts b/samples/meetings-share-to-stage-signing/csharp/Source/MeetingSigning.Web/ClientApp/src/api/fetchClient.ts index 90f89ed875..c9c750ef9a 100644 --- a/samples/meetings-share-to-stage-signing/csharp/Source/MeetingSigning.Web/ClientApp/src/api/fetchClient.ts +++ b/samples/meetings-share-to-stage-signing/csharp/Source/MeetingSigning.Web/ClientApp/src/api/fetchClient.ts @@ -1,10 +1,12 @@ import { merge } from 'lodash'; -import { ApiErrorResponse, ErrorCode } from 'models/ApiErrorResponse'; import * as microsoftTeams from '@microsoft/teams-js'; // This function is for callers where authentication is required. // It makes a fetch client call with an AAD token. -export async function authFetch(urlPath: string, init?: RequestInit) { +export async function authFetch( + urlPath: string, + init?: RequestInit, +) { const token = await microsoftTeams.authentication .getAuthToken() .catch((err) => { @@ -18,31 +20,24 @@ export async function authFetch(urlPath: string, init?: RequestInit) { 'Content-Type': 'application/json;charset=UTF-8', }, }); + return (await fetchClient(urlPath, mergedInit)) as T; } -async function fetchClient(urlPath: string, mergedInit: RequestInit): Promise { +async function fetchClient( + urlPath: string, + mergedInit: RequestInit, +): Promise { const response = await fetch(`/${urlPath}`, mergedInit); if (!response.ok) { - const errorJson: ApiErrorResponse = await response.json(); + const errorJson: any = await response.json(); if (!errorJson) { throw new Error('Error fetching data.'); } - if (errorJson.ErrorCode === ErrorCode.AuthConsentRequired) { - try { - await microsoftTeams.authentication.authenticate({ - url: `${window.location.origin}/auth-start`, - width: 600, - height: 535, - }); - - console.log('Consent provided.'); - return await fetchClient(urlPath, mergedInit); - } catch (error) { - console.error("Failed to get consent: '" + error + "'"); - } + if (errorJson.title) { + throw new Error(`${errorJson.title}`); } throw new Error(`${errorJson.ErrorCode}: ${errorJson.Message}`); diff --git a/samples/meetings-share-to-stage-signing/csharp/Source/MeetingSigning.Web/ClientApp/src/components/ConsentRequest/ConsentRequest.tsx b/samples/meetings-share-to-stage-signing/csharp/Source/MeetingSigning.Web/ClientApp/src/components/ConsentRequest/ConsentRequest.tsx new file mode 100644 index 0000000000..241258271e --- /dev/null +++ b/samples/meetings-share-to-stage-signing/csharp/Source/MeetingSigning.Web/ClientApp/src/components/ConsentRequest/ConsentRequest.tsx @@ -0,0 +1,37 @@ +import * as microsoftTeams from '@microsoft/teams-js'; +import { Button, Flex, Header, Text } from '@fluentui/react-northstar'; + +type ConsentRequestProps = { + callback: (error?: string, result?: string) => void; +}; + +function ConsentRequest({ callback }: ConsentRequestProps) { + const callConsentAuth = async () => { + try { + const result = await microsoftTeams.authentication.authenticate({ + url: `${window.location.origin}/auth-start`, + width: 600, + height: 535, + }); + + console.log('Consent provided.'); + callback(undefined, result); + } catch (error: any) { + console.error(`Failed to get consent: "${error}"`); + callback(error); + } + }; + + return ( + +
+ +