Skip to content

Conversation

@gladjohn
Copy link
Contributor

Added documentation for using managed identities with mTLS proof-of-possession in MSAL.NET, including code examples and installation instructions.

Added documentation for using managed identities with mTLS proof-of-possession in MSAL.NET, including code examples and installation instructions.
@gladjohn gladjohn requested a review from a team as a code owner November 17, 2025 23:46
@gladjohn gladjohn requested a review from Copilot November 17, 2025 23:47
Copilot finished reviewing on behalf of gladjohn November 17, 2025 23:50
Copy link
Contributor

Copilot AI left a 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 adds comprehensive documentation for using mTLS (mutual TLS) proof-of-possession tokens with managed identities in MSAL.NET. The feature is currently in internal preview and extends the existing managed identity experience by binding tokens to X.509 certificates for enhanced security. The documentation provides clear migration paths from Bearer tokens to mTLS PoP tokens, showing developers how to minimally modify their existing code.

Key Changes:

  • Added complete guide for mTLS PoP with managed identities including installation instructions for the preview NuGet package
  • Provided side-by-side code examples comparing Bearer token flow vs. mTLS PoP flow for both system-assigned and user-assigned managed identities
  • Documented how to use binding certificates with HttpClient for mTLS handshakes when calling APIs like Microsoft Graph

@gladjohn
Copy link
Contributor Author

@copilot can you address all open comments

Copy link
Contributor

Copilot AI commented Nov 18, 2025

@gladjohn I've opened a new pull request, #5585, to work on those changes. Once the pull request is ready, I'll request review from you.

@gladjohn
Copy link
Contributor Author

@gladjohn I've opened a new pull request, #5585, to work on those changes. Once the pull request is ready, I'll request review from you.

@copilot why can't you update my PR?

Copy link
Contributor

Copilot AI commented Nov 18, 2025

@gladjohn I've opened a new pull request, #5586, to work on those changes. Once the pull request is ready, I'll request review from you.

@gladjohn gladjohn requested a review from Copilot November 18, 2025 00:05
Copilot finished reviewing on behalf of gladjohn November 18, 2025 00:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Refactor mTLS HttpClient creation and usage for better performance and clarity.
.ConfigureAwait(false);

// result.TokenType == "mtls_pop"
// result.BindingCertificate is the client cert to use for mTLS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// result.BindingCertificate is the client cert to use for mTLS
// result.BindingCertificate is the client cert to use for mTLS in step 4

.ExecuteAsync()
.ConfigureAwait(false);

// result.TokenType == "mtls_pop"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these lines commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a comment in the code.

Copy link
Contributor

@neha-bhargava neha-bhargava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with comments

Updated the documentation for using managed identities with mTLS proof-of-possession in MSAL.NET, including changes to titles, descriptions, and code examples.
@gladjohn gladjohn changed the title Document mTLS PoP usage with managed identities Document mTLS PoP usage in MSAL (all pop features are on internal preview) Nov 20, 2025
Co-authored-by: Neha Bhargava <61847233+neha-bhargava@users.noreply.github.com>
ms.date: 11/17/2025
---

# Use mTLS proof-of-possession (mTLS PoP) tokens in MSAL.NET (internal Microsoft only - preview)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Use mTLS proof-of-possession (mTLS PoP) tokens in MSAL.NET (internal Microsoft only - preview)
# Use mTLS proof-of-possession (mTLS PoP) tokens in MSAL.NET (preview)


## Overview

mTLS PoP builds directly on top of existing MSAL experiences:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc is too long. Can we skip this intro and head directly to code snippets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who is the target audience @bgavrilMS ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application developers. My point is that you can be more concise, for example by using a diff code snippet.

some old code
+ some new code

The following example shows how to use either a user-assigned or system-assigned managed identity.

```csharp
using System.Threading.Tasks;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't include boilerplate

- exposes the `WithMtlsProofOfPossession()` extension for managed identity flows, and
- brings in a native dependency used to attest managed identity keys (for example KeyGuard keys) via Microsoft Azure Attestation (MAA).

### 1.2 Current experience – Bearer (Graph)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include Bearer flow? It's not changed.

using System.Threading.Tasks;
using Microsoft.Identity.Client;

// Choose the appropriate managed identity:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Just give an example with a user assigned managed identity, this is the recommended way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that will lead to questions about is SAMI supported? SAMI is supported.

.Build();

// Microsoft Graph as the target API
const string graphResource = "https://graph.microsoft.com/";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use the scope here, i.e. with .default

I'd also not use a constant string, just set it directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just an extension of what we published in our MSAL usage docs - https://learn.microsoft.com/en-us/entra/msal/dotnet/advanced/managed-identity

Are you suggesting that we change the pattern? and use default everywhere?


AuthenticationResult mtlsPopResult = await mi
.AcquireTokenForManagedIdentity(graphResource)
.WithMtlsProofOfPossession() // <-- new API
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.WithMtlsProofOfPossession() // <-- new API
.WithMtlsProofOfPossession() // <-- new API from Microsoft.Identity.Client.MtlsPoP package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we started off,

This package:

- exposes the `WithMtlsProofOfPossession()` extension for managed identity flows, and
- brings in a native dependency used to attest managed identity keys (for example KeyGuard keys) via Microsoft Azure Attestation (MAA).

wouldn't this be redundant?

> For SNI-based confidential clients, mTLS PoP is provided by the MSAL.NET preview package itself.
> You do **not** need the `Microsoft.Identity.Client.MtlsPop` package for this scenario.

### 2.1 Current experience – Bearer with SN/I certificate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't include this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove ### 2.1 Current experience – Bearer with SN/I certificate

ConfidentialClientApplicationBuilder
.Create(clientId)
.WithAuthority($"https://login.microsoftonline.com/{tenantId}")
.WithAzureRegion("east us") // Required for SNI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a real region


---

## 3. Use mTLS PoP with federated identity credentials (FIC)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should give examples of:

MSI + FIC
OIDC + FIC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants