From f5870ff0bc7c9a5c017d11a273e2de9f7502e714 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Mon, 21 Apr 2025 14:23:47 -0300 Subject: [PATCH 1/5] Remove unnecessary code in .NET FIC sample --- .../AdapterWithErrorHandler.cs | 19 +----------------- .../AuthFederatedCredBot.csproj | 4 ++-- .../Controllers/BotController.cs | 2 +- .../86.bot-authentication-fic/README.md | 20 +++++++++---------- .../86.bot-authentication-fic/Startup.cs | 11 ---------- .../appsettings.json | 2 +- .../wwwroot/default.htm | 2 +- 7 files changed, 16 insertions(+), 44 deletions(-) diff --git a/samples/csharp_dotnetcore/86.bot-authentication-fic/AdapterWithErrorHandler.cs b/samples/csharp_dotnetcore/86.bot-authentication-fic/AdapterWithErrorHandler.cs index 6761e30a1d..322a6d3790 100644 --- a/samples/csharp_dotnetcore/86.bot-authentication-fic/AdapterWithErrorHandler.cs +++ b/samples/csharp_dotnetcore/86.bot-authentication-fic/AdapterWithErrorHandler.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Integration.AspNet.Core; using Microsoft.Bot.Builder.TraceExtensions; using Microsoft.Bot.Connector.Authentication; @@ -12,7 +10,7 @@ namespace Microsoft.BotBuilderSamples { public class AdapterWithErrorHandler : CloudAdapter { - public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger logger, ConversationState conversationState = default) + public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger logger) : base(auth, logger) { OnTurnError = async (turnContext, exception) => @@ -27,21 +25,6 @@ public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger - net6.0 + net8.0 latest - + diff --git a/samples/csharp_dotnetcore/86.bot-authentication-fic/Controllers/BotController.cs b/samples/csharp_dotnetcore/86.bot-authentication-fic/Controllers/BotController.cs index ba57b68f80..77c1cf35b5 100644 --- a/samples/csharp_dotnetcore/86.bot-authentication-fic/Controllers/BotController.cs +++ b/samples/csharp_dotnetcore/86.bot-authentication-fic/Controllers/BotController.cs @@ -5,7 +5,7 @@ using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Integration.AspNet.Core; -namespace bot_authentication_fic.Controllers +namespace Microsoft.BotBuilderSamples.Controllers { // This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot // implementation at runtime. Multiple different IBot implementations running at different endpoints can be diff --git a/samples/csharp_dotnetcore/86.bot-authentication-fic/README.md b/samples/csharp_dotnetcore/86.bot-authentication-fic/README.md index 28cc0ed631..c740dda0c6 100644 --- a/samples/csharp_dotnetcore/86.bot-authentication-fic/README.md +++ b/samples/csharp_dotnetcore/86.bot-authentication-fic/README.md @@ -1,8 +1,8 @@ -# Bot using Federation Identity Credentials +# Bot using Federated Identity Credentials -Bot Framework v4 bot authentication using Federation Identity Credentials (FIC). Currently, FIC feature is supported single tenant bots only. +Bot Framework v4 bot authentication using Federated Identity Credentials (FIC). Currently, FIC feature is supported in single tenant bots only. -This bot has been created using [Bot Framework](https://dev.botframework.com/), is shows how to use the bot authentication capabilities of Azure Bot Service. In this sample, we use federated identity certificate configuration to create the Bot Framework Authentication. +This bot has been created using [Bot Framework](https://dev.botframework.com/), it shows how to use the bot authentication capabilities of Azure Bot Service. In this sample, we use federated identity credentials configuration to create the Bot Framework Authentication. This bot uses `FederatedServiceClientCredentialsFactory` which is registered in Startup.cs. @@ -38,11 +38,11 @@ This bot uses `FederatedServiceClientCredentialsFactory` which is registered in - Record the **Default domain** on the **Overview** tab - Create Azure App and Bot - Create App Registration - - This can be either Single or Multi tenant. + - This should be Single tenant (Currently, FIC feature is supported in single tenant bots only). - Record the Application and Tenant ID's. - - To create trust using the FIC, we need to link the managed identity to the App Registration. On the App Registration: + - To create trust using the FIC, we need to link the managed identity to the App Registration. On the App Registration: - Click on the add credential under **Certificates & Secrets**, **Federated credentials** - - On the Add a credential page, select the Federated credential scenario as **Customer Managed Keys**. + - On the Add a credential page, select the Federated credential scenario as **Managed Identity**. - Select the managed identity that you created in the previous step. - Enter name for the credential and click on **Add**. @@ -51,9 +51,9 @@ This bot uses `FederatedServiceClientCredentialsFactory` which is registered in - For an existing bot - Navigate to the **App Registration** for the **Azure Bot** - - To create trust using the FIC, we need to link the managed identity to the App Registration. On the App Registration: + - To create trust using the FIC, we need to link the managed identity to the App Registration. On the App Registration: - Click on the add credential under **Certificates & Secrets**, **Federated credentials** - - On the Add a credential page, select the Federated credential scenario as **Customer Managed Keys**. + - On the Add a credential page, select the Federated credential scenario as **Managed Identity**. - Select the managed identity that you created in the previous step. - Enter name for the credential and click on **Add**. - Navigate to the **App Service** for the bot @@ -61,7 +61,7 @@ This bot uses `FederatedServiceClientCredentialsFactory` which is registered in - Set appsettings.json variables - - MicrosoftAppType: SingTenant + - MicrosoftAppType: SingleTenant - MicrosoftAppId: {bot-appId} @@ -69,7 +69,7 @@ This bot uses `FederatedServiceClientCredentialsFactory` which is registered in - MicrosoftAppClientId: {clientId of managed identity} -- A bot using Federated Credentials, like UserManagedIdentity, cannot be run locally. It must be deployed to Azure. +- A bot using Federated Credentials, like UserManagedIdentity, cannot be run locally. It must be deployed to Azure. ## Deploy the bot to Azure diff --git a/samples/csharp_dotnetcore/86.bot-authentication-fic/Startup.cs b/samples/csharp_dotnetcore/86.bot-authentication-fic/Startup.cs index a4f40438d0..5be655e0cc 100644 --- a/samples/csharp_dotnetcore/86.bot-authentication-fic/Startup.cs +++ b/samples/csharp_dotnetcore/86.bot-authentication-fic/Startup.cs @@ -42,15 +42,6 @@ public void ConfigureServices(IServiceCollection services) // Create the Bot Adapter with error handling enabled. services.AddSingleton(); - // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.) - services.AddSingleton(); - - // Create the User state. (Used in this bot's Dialog implementation.) - services.AddSingleton(); - - // Create the Conversation state. (Used by the Dialog system itself.) - services.AddSingleton(); - // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. services.AddTransient(); @@ -61,7 +52,6 @@ public void ConfigureServices(IServiceCollection services) } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { @@ -74,7 +64,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) .UseStaticFiles() .UseWebSockets() .UseRouting() - .UseAuthorization() .UseEndpoints(endpoints => { endpoints.MapControllers(); diff --git a/samples/csharp_dotnetcore/86.bot-authentication-fic/appsettings.json b/samples/csharp_dotnetcore/86.bot-authentication-fic/appsettings.json index b3e43e309b..c165f1dafe 100644 --- a/samples/csharp_dotnetcore/86.bot-authentication-fic/appsettings.json +++ b/samples/csharp_dotnetcore/86.bot-authentication-fic/appsettings.json @@ -2,5 +2,5 @@ "MicrosoftAppType": "", "MicrosoftAppId": "", "MicrosoftAppClientId": "", - "MicrosoftAppTenantId": "", + "MicrosoftAppTenantId": "" } diff --git a/samples/csharp_dotnetcore/86.bot-authentication-fic/wwwroot/default.htm b/samples/csharp_dotnetcore/86.bot-authentication-fic/wwwroot/default.htm index ab3f8fdbb7..70696a1e0f 100644 --- a/samples/csharp_dotnetcore/86.bot-authentication-fic/wwwroot/default.htm +++ b/samples/csharp_dotnetcore/86.bot-authentication-fic/wwwroot/default.htm @@ -4,7 +4,7 @@ - bot_authentication_fic + AuthFederatedCredBot