Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CEC Auth changes #2483

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const AuthenticateAndResendRequest = (): React.ReactElement =>
defaultInput: JSON.stringify({
appId: 'b7f8c0a0-6c1d-4a9a-9c0a-2c3f1c0a3b0a',
authenticateParameters: {
url: 'https://www.example.com',
url: 'https://localhost:4000',
width: 100,
height: 100,
isExternal: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import {
AuthTokenRequestParameters,
externalAppAuthenticationForCEC,
IActionExecuteInvokeRequest,
} from '@microsoft/teams-js';
import React from 'react';

import { ApiWithoutInput } from '../utils/ApiWithoutInput';
import { ApiWithTextInput } from '../utils/ApiWithTextInput';
import { ModuleWrapper } from '../utils/ModuleWrapper';

const CheckExternalAppAuthenticationForCECCapability = (): React.ReactElement =>
ApiWithoutInput({
name: 'checkExternalAppAuthenticationCECCapability',
title: 'Check External App Authentication CEC Capability',
onClick: async () =>
`External App Authentication CEC module ${externalAppAuthenticationForCEC.isSupported() ? 'is' : 'is not'} supported`,
});

const AuthenticateWithOAuth = (): React.ReactElement =>
ApiWithTextInput<{
appId: string;
conversationId: string;
authenticateParameters: {
url: string;
width?: number;
height?: number;
isExternal?: boolean;
};
}>({
name: 'AuthenticateWithOAuth',
title: 'Authenticate With OAuth',
onClick: {
validateInput: (input) => {
if (!input.appId) {
throw new Error('appId is required');
}
if (!input.authenticateParameters) {
throw new Error('authenticateParameters is required');
}
},
submit: async (input) => {
await externalAppAuthenticationForCEC.authenticateWithOAuth(input.appId, input.conversationId, {
...input.authenticateParameters,
url: new URL(input.authenticateParameters.url),
});
return 'Completed';
},
},
defaultInput: JSON.stringify({
appId: 'b7f8c0a0-6c1d-4a9a-9c0a-2c3f1c0a3b0a',
conversationId: 'testConversationId',
authenticateParameters: {
url: 'https://localhost:4000',
width: 100,
height: 100,
isExternal: true,
},
}),
});

const AuthenticateWithSSO = (): React.ReactElement =>
ApiWithTextInput<{
appId: string;
conversationId: string;
authTokenRequest: AuthTokenRequestParameters;
}>({
name: 'authenticateWithSSO',
title: 'Authenticate With SSO',
onClick: {
validateInput: (input) => {
if (!input.appId) {
throw new Error('appId is required');
}
if (!input.authTokenRequest) {
throw new Error('authTokenRequest is required');
}
},
submit: async (input, setResult) => {
await externalAppAuthenticationForCEC.authenticateWithSSO(
input.appId,
input.conversationId,
input.authTokenRequest,
);
console.log('completed');
return 'Completed';
},
},
defaultInput: JSON.stringify({
appId: 'b7f8c0a0-6c1d-4a9a-9c0a-2c3f1c0a3b0a',
conversationId: 'testConversationId',
authTokenRequest: {
claims: ['https://graph.microsoft.com'],
silent: true,
},
}),
});

const AuthenticateAndResendRequest = (): React.ReactElement =>
ApiWithTextInput<{
appId: string;
conversationId: string;
authenticateParameters: {
url: string;
width?: number;
height?: number;
isExternal?: boolean;
};
originalRequestInfo: IActionExecuteInvokeRequest;
}>({
name: 'authenticateAndResendRequest',
title: 'Authenticate And Resend Request',
onClick: {
validateInput: (input) => {
if (!input.appId) {
throw new Error('appId is required');
}
if (!input.authenticateParameters) {
throw new Error('authenticateParameters is required');
}
if (!input.originalRequestInfo) {
throw new Error('originalRequestInfo is required');
}
},
submit: async (input) => {
const result = await externalAppAuthenticationForCEC.authenticateAndResendRequest(
input.appId,
input.conversationId,
{ ...input.authenticateParameters, url: new URL(input.authenticateParameters.url) },
input.originalRequestInfo,
);
return JSON.stringify(result);
},
},
defaultInput: JSON.stringify({
appId: 'b7f8c0a0-6c1d-4a9a-9c0a-2c3f1c0a3b0a',
conversationId: 'testConversationId',
authenticateParameters: {
url: 'https://localhost:4000',
width: 100,
height: 100,
isExternal: true,
},
originalRequestInfo: {
requestType: 'ActionExecuteInvokeRequest',
type: 'Action.Execute',
id: 'id1',
verb: 'verb1',
data: 'data1',
},
}),
});
const AuthenticateWithSSOAndResendRequest = (): React.ReactElement =>
ApiWithTextInput<{
appId: string;
conversationId: string;
authTokenRequest: AuthTokenRequestParameters;
originalRequestInfo: IActionExecuteInvokeRequest;
}>({
name: 'authenticateWithSSOAndResendRequest',
title: 'Authenticate With SSO And Resend Request',
onClick: {
validateInput: (input) => {
if (!input.appId) {
throw new Error('appId is required');
}
if (!input.authTokenRequest) {
throw new Error('authTokenRequest is required');
}
if (!input.originalRequestInfo) {
throw new Error('originalRequestInfo is required');
}
},
submit: async (input) => {
const result = await externalAppAuthenticationForCEC.authenticateWithSSOAndResendRequest(
input.appId,
input.conversationId,
input.authTokenRequest,
input.originalRequestInfo,
);
return JSON.stringify(result);
},
},
defaultInput: JSON.stringify({
appId: 'b7f8c0a0-6c1d-4a9a-9c0a-2c3f1c0a3b0a',
conversationId: 'testConversationId',
authTokenRequest: {
claims: ['https://graph.microsoft.com'],
silent: true,
},
originalRequestInfo: {
requestType: 'ActionExecuteInvokeRequest',
type: 'Action.Execute',
id: 'id1',
verb: 'verb1',
data: 'data1',
},
}),
});

const ExternalAppAuthenticationForCECAPIs = (): React.ReactElement => (
<ModuleWrapper title="External App Authentication for CEC">
<CheckExternalAppAuthenticationForCECCapability />
<AuthenticateWithOAuth />
<AuthenticateWithSSO />
<AuthenticateAndResendRequest />
<AuthenticateWithSSOAndResendRequest />
</ModuleWrapper>
);

export default ExternalAppAuthenticationForCECAPIs;
2 changes: 2 additions & 0 deletions apps/teams-test-app/src/pages/TestApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import PeopleAPIs from '../components/PeopleAPIs';
import ChatAPIs from '../components/privateApis/ChatAPIs';
import CopilotAPIs from '../components/privateApis/CopilotAPIs';
import ExternalAppAuthenticationAPIs from '../components/privateApis/ExternalAppAuthenticationAPIs';
import ExternalAppAuthenticationForCECAPIs from '../components/privateApis/ExternalAppAuthenticationCECAPIs';
import ExternalAppCardActionsAPIs from '../components/privateApis/ExternalAppCardActionsAPIs';
import ExternalAppCommandsAPIs from '../components/privateApis/ExternalAppCommandsAPIs';
import FilesAPIs from '../components/privateApis/FilesAPIs';
Expand Down Expand Up @@ -93,6 +94,7 @@ export const TestApp: React.FC = () => {
<DialogUrlBotAPIs />
<DialogUrlParentCommunicationAPIs childWindowRef={dialogWindowRef} />
<ExternalAppAuthenticationAPIs />
<ExternalAppAuthenticationForCECAPIs />
<ExternalAppCardActionsAPIs />
<ExternalAppCommandsAPIs />
<FilesAPIs />
Expand Down
4 changes: 4 additions & 0 deletions packages/teams-js/src/internal/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export const enum ApiName {
ExternalAppAuthentication_AuthenticateWithSSOAndResendRequest = 'externalAppAuthentication.authenticateWithSSOAndResendRequest',
ExternalAppAuthentication_AuthenticateWithOauth2 = 'externalAppAuthentication.authenticateWithOauth2',
ExternalAppAuthentication_AuthenticateWithPowerPlatformConnectorPlugins = 'externalAppAuthentication.authenticateWithPowerPlatformConnectorPlugins',
ExternalAppAuthenticationForCEC_AuthenticateWithOauth = 'externalAppAuthentication.cec.authenticateWithOauth',
ExternalAppAuthenticationForCEC_AuthenticateWithSSO = 'externalAppAuthentication.cec.AuthenticateWithSSO',
ExternalAppAuthenticationForCEC_SSOAuthCompleted = 'externalAppAuthentication.cec.SSOAuthCompleted',
ExternalAppAuthenticationForCEC_OAuthCompleted = 'externalAppAuthentication.cec.OAuthCompleted',
ExternalAppCardActions_ProcessActionOpenUrl = 'externalAppCardActions.processActionOpenUrl',
ExternalAppCardActions_ProcessActionSubmit = 'externalAppCardActions.processActionSubmit',
ExternalAppCommands_ProcessActionCommands = 'externalAppCommands.processActionCommand',
Expand Down
Loading
Loading