Skip to content
Draft
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
16 changes: 16 additions & 0 deletions Microsoft.Teams.sln
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.Dialogs", "Samples\Samples.Dialogs\Samples.Dialogs.csproj", "{D406AE11-285C-4AC8-862B-C755386D15F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.MessageExtensions", "Samples\Samples.MessageExtensions\Samples.MessageExtensions.csproj", "{C4DDD35D-CCDC-4EBB-94F6-F2E4E4406AA8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Teams.Plugins.External.McpClient.Tests", "Tests\Microsoft.Teams.Plugins.External.McpClient.Tests\Microsoft.Teams.Plugins.External.McpClient.Tests.csproj", "{783599E3-9841-4377-9590-4A5D9EC0023D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.AzureIdentity", "Samples\Samples.AzureIdentity\Samples.AzureIdentity.csproj", "{4FF887BF-A872-4752-94EB-610EF19800E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -486,6 +489,18 @@ Global
{783599E3-9841-4377-9590-4A5D9EC0023D}.Release|x64.Build.0 = Release|Any CPU
{783599E3-9841-4377-9590-4A5D9EC0023D}.Release|x86.ActiveCfg = Release|Any CPU
{783599E3-9841-4377-9590-4A5D9EC0023D}.Release|x86.Build.0 = Release|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Debug|x64.ActiveCfg = Debug|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Debug|x64.Build.0 = Debug|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Debug|x86.ActiveCfg = Debug|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Debug|x86.Build.0 = Debug|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Release|Any CPU.Build.0 = Release|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Release|x64.ActiveCfg = Release|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Release|x64.Build.0 = Release|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Release|x86.ActiveCfg = Release|Any CPU
{4FF887BF-A872-4752-94EB-610EF19800E2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -527,6 +542,7 @@ Global
{D406AE11-285C-4AC8-862B-C755386D15F6} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA}
{C4DDD35D-CCDC-4EBB-94F6-F2E4E4406AA8} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA}
{783599E3-9841-4377-9590-4A5D9EC0023D} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
{4FF887BF-A872-4752-94EB-610EF19800E2} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {378263F2-C2B2-4DB1-83CF-CA228AF03ABF}
Expand Down
64 changes: 64 additions & 0 deletions Samples/Samples.AzureIdentity/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.AppConfig;
using Microsoft.Teams.Api.Activities;
using Microsoft.Teams.Api.Auth;
using Microsoft.Teams.Apps;
using Microsoft.Teams.Apps.Activities;
using Microsoft.Teams.Apps.Annotations;
using Microsoft.Teams.Apps.Extensions;
using Microsoft.Teams.Plugins.AspNetCore.DevTools.Extensions;
using Microsoft.Teams.Plugins.AspNetCore.Extensions;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
builder.Services.AddTransient<Controller>();

var botClientId = builder.Configuration["AzureIdentity:BotClientId"] ?? "";
var managedIdentityClientId = builder.Configuration["AzureIdentity:ManagedIdentityClientId"];

var managedIdentityId = string.IsNullOrEmpty(managedIdentityClientId)
? ManagedIdentityId.SystemAssigned
: ManagedIdentityId.WithUserAssignedClientId(managedIdentityClientId);

var msalApp = ManagedIdentityApplicationBuilder.Create(managedIdentityId).Build();

var appOptions = new AppOptions
{
Credentials = new TokenCredentials(botClientId, async (_, scopes) =>
{
var scopesToUse = scopes.Length > 0 ? scopes : new[] { "https://api.botframework.com/.default" };
var result = await msalApp.AcquireTokenForManagedIdentity(scopesToUse[0]).ExecuteAsync();
return new TokenResponse { TokenType = "Bearer", AccessToken = result.AccessToken };
})
};

builder.AddTeams(appOptions).AddTeamsDevTools();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}

app.UseHttpsRedirection();
app.UseTeams();
app.Run();

[TeamsController]
public class Controller
{
[Activity]
public async Task OnActivity(IContext<Activity> context, [Context] IContext.Next next)
{
context.Log.Info($"Bot App ID: {context.AppId}");
await next();
}

[Message]
public async Task OnMessage([Context] MessageActivity activity, [Context] IContext.Client client)
{
await client.Typing();
await client.Send($"You said: '{activity.Text}'\n\nThis bot is authenticated using Azure Managed Identity!");
}
}
25 changes: 25 additions & 0 deletions Samples/Samples.AzureIdentity/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "openapi/v1.json",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:3978"
},
"https": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "openapi/v1.json",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7239;http://localhost:3978"
}
},
"$schema": "http://json.schemastore.org/launchsettings.json"
}
Loading