Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/samples/CompatBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
compatAdapter.Use(new MyCompatMiddleware());

app.MapPost("/api/messages", async (IBotFrameworkHttpAdapter adapter, IBot bot, HttpRequest request, HttpResponse response, CancellationToken ct) =>
await adapter.ProcessAsync(request, response, bot, ct));
await adapter.ProcessAsync(request, response, bot, ct)).RequireAuthorization();

app.MapGet("/api/notify/{cid}", async (IBotFrameworkHttpAdapter adapter, string cid, CancellationToken ct) =>
{
Expand Down
49 changes: 49 additions & 0 deletions core/samples/TeamsBot/Properties/launchSettings.TEMPLATE.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"profiles": {
"TeamsBot-MsalConfig": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://localhost:3978",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"Logging__LogLevel__Microsoft.Teams": "Trace",
"Logging__LogLevel__System.Net.Http.HttpClient": "Warning",
"AzureAd__Instance": "",
"AzureAd__Scope": "",
"AzureAd__ClientId": "",
"AzureAd__TenantId": "",
"AzureAd__ClientCredentials__0__SourceType": "ClientSecret",
"AzureAd__ClientCredentials__0__ClientSecret": ""
}
},
"TeamsBot-CoreConfig": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://localhost:3978",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"Logging__LogLevel__Microsoft.Teams": "Trace",
"Logging__LogLevel__System.Net.Http.HttpClient": "Warning",
"Scope": "",
"TENANT_ID": "",
"CLIENT_ID": "",
"CLIENT_SECRET": "",
"MANAGED_IDENTITY_CLIENT_ID": ""
}
},
"TeamsBot-BFConfig": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://localhost:3978",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"Logging__LogLevel__Microsoft.Teams": "Trace",
"Logging__LogLevel__System.Net.Http.HttpClient": "Warning",
"Scope": "",
"MicrosoftAppPassword": "",
"MicrosoftAppId": "",
"MicrosoftAppTenantId": ""
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// Licensed under the MIT License.

using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Identity.Abstractions;
using Microsoft.Teams.Bot.Core.Hosting;

namespace Microsoft.Teams.Bot.Apps;
Expand Down Expand Up @@ -47,30 +43,13 @@ public static IServiceCollection AddTeamsBotApplication(this IServiceCollection
/// <returns>The updated WebApplicationBuilder instance.</returns>
public static IServiceCollection AddTeamsBotApplication<TApp>(this IServiceCollection services, string sectionName = "AzureAd") where TApp : TeamsBotApplication
{
// Register options to defer configuration reading until ServiceProvider is built
services.AddOptions<BotClientOptions>()
.Configure<IConfiguration>((options, configuration) =>
{
options.Scope = "https://api.botframework.com/.default";
if (!string.IsNullOrEmpty(configuration[$"{sectionName}:Scope"]))
options.Scope = configuration[$"{sectionName}:Scope"]!;
if (!string.IsNullOrEmpty(configuration["Scope"]))
options.Scope = configuration["Scope"]!;
options.SectionName = sectionName;
});
// Resolve BotConfig to get authentication configuration
BotConfig botConfig = BotConfig.Resolve(services, sectionName);

services.AddHttpClient<TeamsApiClient>(TeamsApiClient.TeamsHttpClientName)
.AddHttpMessageHandler(sp =>
{
BotClientOptions options = sp.GetRequiredService<IOptions<BotClientOptions>>().Value;
return new BotAuthenticationHandler(
sp.GetRequiredService<IAuthorizationHeaderProvider>(),
sp.GetRequiredService<ILogger<BotAuthenticationHandler>>(),
options.Scope,
sp.GetService<IOptions<ManagedIdentityOptions>>());
});
// Reuse AddBotClient infrastructure for TeamsApiClient
services.AddBotClient<TeamsApiClient>(TeamsApiClient.TeamsHttpClientName, botConfig);

services.AddBotApplication<TApp>();
services.AddBotApplication<TApp>(sectionName);
return services;
}

Expand Down
Loading
Loading