From d30534b95ddd02e27781441332f17a6d94f22e43 Mon Sep 17 00:00:00 2001 From: Yimin-Jin <139844715+Yimin-Jin@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:22:13 +0800 Subject: [PATCH 1/2] feat: add scaffolding logic for copliot plugin template (#11855) --- .../generator/templates/templateNames.ts | 26 +++++++++++--- .../coordinator/coordinator.create.test.ts | 36 +++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/packages/fx-core/src/component/generator/templates/templateNames.ts b/packages/fx-core/src/component/generator/templates/templateNames.ts index 676d5733fb..44a8b6eb2e 100644 --- a/packages/fx-core/src/component/generator/templates/templateNames.ts +++ b/packages/fx-core/src/component/generator/templates/templateNames.ts @@ -281,10 +281,6 @@ export const inputsToTemplateName: Map<{ [key: string]: any }, TemplateNames> = { [QuestionNames.Capabilities]: CapabilityOptions.aiAssistantBot().id }, TemplateNames.AIAssistantBot, ], - [ - { [QuestionNames.Capabilities]: CapabilityOptions.copilotPluginNewApi().id }, - TemplateNames.ApiPluginFromScratch, - ], [ { [QuestionNames.Capabilities]: CapabilityOptions.m365SearchMe().id, @@ -355,4 +351,26 @@ export const inputsToTemplateName: Map<{ [key: string]: any }, TemplateNames> = }, TemplateNames.CustomCopilotAssistantAssistantsApi, ], + // Copilot Plugin + [ + { + [QuestionNames.Capabilities]: CapabilityOptions.copilotPluginNewApi().id, + [QuestionNames.ApiAuth]: ApiAuthOptions.none().id, + }, + TemplateNames.ApiPluginFromScratch, + ], + [ + { + [QuestionNames.Capabilities]: CapabilityOptions.copilotPluginNewApi().id, + [QuestionNames.ApiAuth]: ApiAuthOptions.apiKey().id, + }, + TemplateNames.ApiPluginFromScratchBearer, + ], + [ + { + [QuestionNames.Capabilities]: CapabilityOptions.copilotPluginNewApi().id, + [QuestionNames.ApiAuth]: ApiAuthOptions.oauth().id, + }, + TemplateNames.ApiPluginFromScratchOAuth, + ], ]); diff --git a/packages/fx-core/tests/component/coordinator/coordinator.create.test.ts b/packages/fx-core/tests/component/coordinator/coordinator.create.test.ts index d5847ae04b..5ea3f141c2 100644 --- a/packages/fx-core/tests/component/coordinator/coordinator.create.test.ts +++ b/packages/fx-core/tests/component/coordinator/coordinator.create.test.ts @@ -934,6 +934,42 @@ const V3Version = MetadataV3.projectVersion; const res = await coordinator.create(v3ctx, inputs); assert.isTrue(res.isOk()); }); + + it("create API Plugin with api-key auth (feature flag enabled)", async () => { + const v3ctx = createContext(); + v3ctx.userInteraction = new MockedUserInteraction(); + + const inputs: Inputs = { + platform: Platform.VSCode, + folder: ".", + [QuestionNames.ProjectType]: ProjectTypeOptions.copilotPlugin().id, + [QuestionNames.Capabilities]: CapabilityOptions.copilotPluginNewApi().id, + [QuestionNames.ApiAuth]: ApiAuthOptions.apiKey().id, + [QuestionNames.ProgrammingLanguage]: "javascript", + [QuestionNames.AppName]: randomAppName(), + [QuestionNames.Scratch]: ScratchOptions.yes().id, + }; + const res = await coordinator.create(v3ctx, inputs); + assert.isTrue(res.isOk()); + }); + + it("create API Plugin with OAuth (feature flag enabled)", async () => { + const v3ctx = createContext(); + v3ctx.userInteraction = new MockedUserInteraction(); + + const inputs: Inputs = { + platform: Platform.VSCode, + folder: ".", + [QuestionNames.ProjectType]: ProjectTypeOptions.copilotPlugin().id, + [QuestionNames.Capabilities]: CapabilityOptions.copilotPluginNewApi().id, + [QuestionNames.ApiAuth]: ApiAuthOptions.oauth().id, + [QuestionNames.ProgrammingLanguage]: "javascript", + [QuestionNames.AppName]: randomAppName(), + [QuestionNames.Scratch]: ScratchOptions.yes().id, + }; + const res = await coordinator.create(v3ctx, inputs); + assert.isTrue(res.isOk()); + }); }); }); From ec004add2ae168db86853815743053417f71d659 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Wed, 19 Jun 2024 11:29:23 +0800 Subject: [PATCH 2/2] refactor: update AAD manifest and API specification files (#11853) --- .../csharp/api-plugin-from-scratch-oauth/aad.manifest.json.tpl | 2 +- .../appPackage/apiSpecificationFile/repair.dev.yml | 2 +- .../csharp/api-plugin-from-scratch-oauth/infra/azure.bicep | 2 +- .../js/api-plugin-from-scratch-oauth/aad.manifest.json.tpl | 2 +- .../appPackage/apiSpecificationFile/repair.dev.yml | 2 +- templates/js/api-plugin-from-scratch-oauth/infra/azure.bicep | 2 +- .../ts/api-plugin-from-scratch-oauth/aad.manifest.json.tpl | 2 +- .../appPackage/apiSpecificationFile/repair.dev.yml | 2 +- templates/ts/api-plugin-from-scratch-oauth/infra/azure.bicep | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/templates/csharp/api-plugin-from-scratch-oauth/aad.manifest.json.tpl b/templates/csharp/api-plugin-from-scratch-oauth/aad.manifest.json.tpl index aae45fdd43..980545a890 100644 --- a/templates/csharp/api-plugin-from-scratch-oauth/aad.manifest.json.tpl +++ b/templates/csharp/api-plugin-from-scratch-oauth/aad.manifest.json.tpl @@ -35,6 +35,6 @@ } ], "identifierUris": [ - "api://${{OPENAPI_SERVER_DOMAIN}}/${{AAD_APP_CLIENT_ID}}" + "api://${{AAD_APP_CLIENT_ID}}" ] } \ No newline at end of file diff --git a/templates/csharp/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml b/templates/csharp/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml index b3c79d5bd3..8a7307262a 100644 --- a/templates/csharp/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml +++ b/templates/csharp/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml @@ -16,7 +16,7 @@ components: authorizationUrl: https://login.microsoftonline.com/${{AAD_APP_TENANT_ID}}/oauth2/v2.0/authorize tokenUrl: https://login.microsoftonline.com/${{AAD_APP_TENANT_ID}}/oauth2/v2.0/token scopes: - repairs_read: Read repair records + api://${{AAD_APP_CLIENT_ID}}/repairs_read: Read repair records paths: /repairs: diff --git a/templates/csharp/api-plugin-from-scratch-oauth/infra/azure.bicep b/templates/csharp/api-plugin-from-scratch-oauth/infra/azure.bicep index fd73abeddd..3821e1afdb 100644 --- a/templates/csharp/api-plugin-from-scratch-oauth/infra/azure.bicep +++ b/templates/csharp/api-plugin-from-scratch-oauth/infra/azure.bicep @@ -94,7 +94,7 @@ resource functionApp 'Microsoft.Web/sites@2021-02-01' = { } var apiEndpoint = 'https://${functionApp.properties.defaultHostName}' var oauthAuthority = uri(aadAppOauthAuthorityHost, aadAppTenantId) -var aadApplicationIdUri = 'api://${functionApp.properties.defaultHostName}/${aadAppClientId}' +var aadApplicationIdUri = 'api://${aadAppClientId}' // Configure Azure Functions to use Azure AD for authentication. resource authSettings 'Microsoft.Web/sites/config@2021-02-01' = { diff --git a/templates/js/api-plugin-from-scratch-oauth/aad.manifest.json.tpl b/templates/js/api-plugin-from-scratch-oauth/aad.manifest.json.tpl index aae45fdd43..980545a890 100644 --- a/templates/js/api-plugin-from-scratch-oauth/aad.manifest.json.tpl +++ b/templates/js/api-plugin-from-scratch-oauth/aad.manifest.json.tpl @@ -35,6 +35,6 @@ } ], "identifierUris": [ - "api://${{OPENAPI_SERVER_DOMAIN}}/${{AAD_APP_CLIENT_ID}}" + "api://${{AAD_APP_CLIENT_ID}}" ] } \ No newline at end of file diff --git a/templates/js/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml b/templates/js/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml index 319f51388c..27afb73066 100644 --- a/templates/js/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml +++ b/templates/js/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml @@ -16,7 +16,7 @@ components: authorizationUrl: https://login.microsoftonline.com/${{AAD_APP_TENANT_ID}}/oauth2/v2.0/authorize tokenUrl: https://login.microsoftonline.com/${{AAD_APP_TENANT_ID}}/oauth2/v2.0/token scopes: - repairs_read: Read repair records + api://${{AAD_APP_CLIENT_ID}}/repairs_read: Read repair records paths: /repairs: get: diff --git a/templates/js/api-plugin-from-scratch-oauth/infra/azure.bicep b/templates/js/api-plugin-from-scratch-oauth/infra/azure.bicep index ed508bfc41..bfe77f8ac9 100644 --- a/templates/js/api-plugin-from-scratch-oauth/infra/azure.bicep +++ b/templates/js/api-plugin-from-scratch-oauth/infra/azure.bicep @@ -94,7 +94,7 @@ resource functionApp 'Microsoft.Web/sites@2021-02-01' = { } var apiEndpoint = 'https://${functionApp.properties.defaultHostName}' var oauthAuthority = uri(aadAppOauthAuthorityHost, aadAppTenantId) -var aadApplicationIdUri = 'api://${functionApp.properties.defaultHostName}/${aadAppClientId}' +var aadApplicationIdUri = 'api://${aadAppClientId}' // Configure Azure Functions to use Azure AD for authentication. resource authSettings 'Microsoft.Web/sites/config@2021-02-01' = { diff --git a/templates/ts/api-plugin-from-scratch-oauth/aad.manifest.json.tpl b/templates/ts/api-plugin-from-scratch-oauth/aad.manifest.json.tpl index aae45fdd43..980545a890 100644 --- a/templates/ts/api-plugin-from-scratch-oauth/aad.manifest.json.tpl +++ b/templates/ts/api-plugin-from-scratch-oauth/aad.manifest.json.tpl @@ -35,6 +35,6 @@ } ], "identifierUris": [ - "api://${{OPENAPI_SERVER_DOMAIN}}/${{AAD_APP_CLIENT_ID}}" + "api://${{AAD_APP_CLIENT_ID}}" ] } \ No newline at end of file diff --git a/templates/ts/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml b/templates/ts/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml index 319f51388c..27afb73066 100644 --- a/templates/ts/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml +++ b/templates/ts/api-plugin-from-scratch-oauth/appPackage/apiSpecificationFile/repair.dev.yml @@ -16,7 +16,7 @@ components: authorizationUrl: https://login.microsoftonline.com/${{AAD_APP_TENANT_ID}}/oauth2/v2.0/authorize tokenUrl: https://login.microsoftonline.com/${{AAD_APP_TENANT_ID}}/oauth2/v2.0/token scopes: - repairs_read: Read repair records + api://${{AAD_APP_CLIENT_ID}}/repairs_read: Read repair records paths: /repairs: get: diff --git a/templates/ts/api-plugin-from-scratch-oauth/infra/azure.bicep b/templates/ts/api-plugin-from-scratch-oauth/infra/azure.bicep index 7e76102608..f9eafef664 100644 --- a/templates/ts/api-plugin-from-scratch-oauth/infra/azure.bicep +++ b/templates/ts/api-plugin-from-scratch-oauth/infra/azure.bicep @@ -94,7 +94,7 @@ resource functionApp 'Microsoft.Web/sites@2021-02-01' = { } var apiEndpoint = 'https://${functionApp.properties.defaultHostName}' var oauthAuthority = uri(aadAppOauthAuthorityHost, aadAppTenantId) -var aadApplicationIdUri = 'api://${functionApp.properties.defaultHostName}/${aadAppClientId}' +var aadApplicationIdUri = 'api://${aadAppClientId}' // Configure Azure Functions to use Azure AD for authentication. resource authSettings 'Microsoft.Web/sites/config@2021-02-01' = {