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,212 @@
import {
AppId,
AuthTokenRequestParameters,
externalAppAuthenticationForCEA,
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 CheckExternalAppAuthenticationForCEACapability = (): React.ReactElement =>
ApiWithoutInput({
name: 'checkExternalAppAuthenticationCEACapability',
title: 'Check External App Authentication CEA Capability',
onClick: async () =>
`External App Authentication CEA module ${externalAppAuthenticationForCEA.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 externalAppAuthenticationForCEA.authenticateWithOAuth(new AppId(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) => {
await externalAppAuthenticationForCEA.authenticateWithSSO(
new AppId(input.appId),
input.conversationId,
input.authTokenRequest,
);

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 externalAppAuthenticationForCEA.authenticateAndResendRequest(
new AppId(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 externalAppAuthenticationForCEA.authenticateWithSSOAndResendRequest(
new AppId(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 ExternalAppAuthenticationForCEAAPIs = (): React.ReactElement => (
<ModuleWrapper title="External App Authentication for CEA">
<CheckExternalAppAuthenticationForCEACapability />
<AuthenticateWithOAuth />
<AuthenticateWithSSO />
<AuthenticateAndResendRequest />
<AuthenticateWithSSOAndResendRequest />
</ModuleWrapper>
);

export default ExternalAppAuthenticationForCEAAPIs;
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 ExternalAppAuthenticationForCEAAPIs from '../components/privateApis/ExternalAppAuthenticationForCEAAPIs';
import ExternalAppCardActionsAPIs from '../components/privateApis/ExternalAppCardActionsAPIs';
import ExternalAppCardActionsForCEAAPIs from '../components/privateApis/ExternalAppCardActionsForCEAAPIs';
import ExternalAppCommandsAPIs from '../components/privateApis/ExternalAppCommandsAPIs';
Expand Down Expand Up @@ -114,6 +115,7 @@ export const TestApp: React.FC = () => {
<DialogUrlBotAPIs />
<DialogUrlParentCommunicationAPIs childWindowRef={dialogWindowRef} />
<ExternalAppAuthenticationAPIs />
<ExternalAppAuthenticationForCEAAPIs />
<ExternalAppCardActionsAPIs />
<ExternalAppCardActionsForCEAAPIs />
<ExternalAppCommandsAPIs />
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 @@ -123,6 +123,10 @@ export const enum ApiName {
ExternalAppAuthentication_AuthenticateWithSSOAndResendRequest = 'externalAppAuthentication.authenticateWithSSOAndResendRequest',
ExternalAppAuthentication_AuthenticateWithOauth2 = 'externalAppAuthentication.authenticateWithOauth2',
ExternalAppAuthentication_AuthenticateWithPowerPlatformConnectorPlugins = 'externalAppAuthentication.authenticateWithPowerPlatformConnectorPlugins',
ExternalAppAuthenticationForCEA_AuthenticateWithOauth = 'externalAppAuthentication.cea.authenticateWithOauth',
ExternalAppAuthenticationForCEA_AuthenticateWithSSO = 'externalAppAuthentication.cea.AuthenticateWithSSO',
ExternalAppAuthenticationForCEA_SSOAuthCompleted = 'externalAppAuthentication.cea.SSOAuthCompleted',
ExternalAppAuthenticationForCEA_OAuthCompleted = 'externalAppAuthentication.cea.OAuthCompleted',
ExternalAppCardActions_ProcessActionOpenUrl = 'externalAppCardActions.processActionOpenUrl',
ExternalAppCardActions_ProcessActionSubmit = 'externalAppCardActions.processActionSubmit',
ExternalAppCardActionsForCEA_ProcessActionOpenUrl = 'externalAppCardActionsForCEA.processActionOpenUrl',
Expand Down
Loading
Loading