-
Notifications
You must be signed in to change notification settings - Fork 15
Add Azure Managed Identity authentication sample using MSAL (Microsoft.Identity.Client) #183
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: aacebo <[email protected]>
|
@copilot don't add anything to the core libraries, just create a sample showcasing how to use teams.net/Libraries/Microsoft.Teams.Api/Auth/TokenCredentials.cs at main · microsoft/teams.net with |
…m class Co-authored-by: aacebo <[email protected]>
Updated the implementation to use the existing Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot get rid of |
Co-authored-by: aacebo <[email protected]>
Simplified the code to use the existing Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a comprehensive sample demonstrating Azure Managed Identity authentication for Teams bots using the existing TokenCredentials class. The sample eliminates the need to store client secrets by leveraging Azure's managed identity capabilities and the Azure.Identity SDK. It supports three authentication modes: system-assigned managed identity, user-assigned managed identity, and DefaultAzureCredential for flexible local development.
Key Changes:
- New Samples.AzureIdentity project with minimal Program.cs demonstrating integration between Azure.Identity SDK and existing Teams SDK authentication
- Comprehensive 342-line README with setup instructions, troubleshooting guide, and security best practices
- Configuration files supporting multiple authentication modes without storing sensitive credentials
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Samples.AzureIdentity/Program.cs | Implements bot authentication using Azure.Identity SDK with TokenCredentials and a TokenFactory delegate |
| Samples.AzureIdentity/Samples.AzureIdentity.csproj | Project configuration targeting .NET 9.0 with Azure.Identity package reference |
| Samples.AzureIdentity/README.md | Comprehensive documentation covering setup, deployment, troubleshooting, and security best practices |
| Samples.AzureIdentity/appsettings.json | Configuration file for managed identity settings without client secrets |
| Samples.AzureIdentity/appsettings.Development.json | Development-specific logging configuration |
| Samples.AzureIdentity/Properties/launchSettings.json | Launch profiles for local development on port 3978 |
| Microsoft.Teams.sln | Solution file updated to include new Samples.AzureIdentity project |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| principalId=$(az identity show --name <identity-name> --resource-group <resource-group> --query principalId -o tsv) | ||
|
|
||
| # Grant the role assignment | ||
| az role assignment create --role "BotService Contributor" \ |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The role name appears to be incorrect. Azure typically uses role names like 'BotService Contributor' or 'Contributor', but 'BotService Contributor' is not a standard Azure built-in role. This should be verified and corrected to use an actual Azure RBAC role such as 'Contributor' or a custom role specific to Bot Service.
| az role assignment create --role "BotService Contributor" \ | |
| az role assignment create --role "Contributor" \ |
|
@copilot Tag |
Microsoft.Identity.Client (MSAL) doesn't have built-in support for Managed Identity authentication in the same way Azure.Identity does. MSAL is primarily designed for user/application authentication with client secrets/certificates, while Azure.Identity is the recommended library from Microsoft for managed identity scenarios. However, if you'd still prefer MSAL for specific integration reasons, I can create a sample using MSAL's |
Co-authored-by: rido-min <[email protected]>
Updated to use Microsoft.Identity.Client (MSAL) with Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot remove any usage of client secret, you should only be using managed identity to authenticate |
Co-authored-by: aacebo <[email protected]>
The sample already uses only managed identity - no client secrets are present in the code or configuration. Updated the README to make this explicitly clear with prominent notes that this sample uses ONLY managed identity authentication and does not use client secrets. (commit: 8a3f2d1) |
Created sample showcasing Azure Identity authentication using existing SDK classes:
Summary
This sample demonstrates how to use Azure Managed Identity authentication with Microsoft.Identity.Client (MSAL) and the existing
TokenCredentialsclass from the Teams SDK.Key Points:
Implementation:
Documentation Updates:
Testing:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.