-
Notifications
You must be signed in to change notification settings - Fork 345
Proof Of Possession (PoP) tokens
This is a new feature introduced in MSAL 4.8. Currently it is supported only for confidential client flows.
Bearer tokens are the norm in modern identity flows, however they are vulnerable to being stolen and used to access a protected resource.
Proof of Possession (PoP) tokens mitigate this threat via 2 mechanisms:
- they are bound to the user / machine that wants to access a protected resource, via a public / private key pair
- they are bound to the protected resource itself, i.e. a token that is used to access
GET https://contoso.com/transactions
cannot be used to accessGET https://contoso.com/tranfer/100
For more details, see RFC 7800
See the full code sample show casing a daemon app using AcquireTokenForClient with Pop to call an API protected with Pop: https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2/tree/master/4-Call-OwnApi-Pop
//The PoP token will be bound to this user / machine and to `GET https://www.contoso.com/tranfers` (the query params are not bound)
//Request URI is required in the PopAuthenticationConfiguration constructor
PopAuthenticationConfiguration popConfig = new PopAuthenticationConfiguration(new Uri("https://www.contoso.com/tranfers?user=me"));
//HttpMethod is optional
popConfig.HttpMethod = HttpMethod.Get;
// Server nonce (optional)
// popConfig.Nonce =
//PopCryptoProvider is optional. Do not set to use MSAL'S internal implementation.
popConfig.PopCryptoProvider = new ECDCertificatePopCryptoProvider();
var cca = ConfidentialClientApplicationBuilder.Create(CLIENT_ID)
.WithExperimentalFeatures() // Currently POP is marked as an experimental feature
.Build();
result = await cca
.AcquireTokenForClient (new[] { "scope"})
.WithProofOfPossession(popConfig)
.ExecuteAsync()
.ConfigureAwait(false);
//The PoP token will be available on the AuthenticationResult returned form the acquireToken call
result.AccessToken;
//To create the auth header
var authHeader = new AuthenticationHeaderValue(result.TokenType, result.AccessToken);
An RSA key pair of length 2048 is generated by MSAL and stored in memory which will be cycled every 8 hours. For more details please inspect the code here and here
To use PoP, you first need to protect an API with PoP. More details in the wiki.
If you are writing a new API, you protected using PoP exclusively and require clients to generate PoP tokens. If you are upgrading an existing API, consider supporting both Bearer and PoP tokens for a while, to allow clients to migrate. MSAL supports requesting both Bearer and PoP tokens for the same resource.
The POP feature in MSAL allows users to provide their own key management for additional control over cryptograpgic operations in POP. The interface is An abstraction over an the asymmetric key operations needed by POP, that encapsulates a pair of public and private keys and some typical crypto operations. All symetric operations are SHA256.
Important: The 2 properties and the sign method on this interface will be called at different times but MUST return details of the same private / public key pair, i.e. do not change to a different key pair mid way. Best to have this class immutable. Ideally there should be a single public / private key pair associated with a machine, so implementers of this interface should consider exposing a singleton. Please click the links below for more information.
Example RSA key implementation
Example ECD key implementation
POP tokens on public client flows can be achieved with the use of the new preview WAM Broker (See Here) on windows.
In order to utilize the new broker to perform proof-of-possession, see the code snippet below.
using Microsoft.Identity.Client.Broker; //Required for the use of the preview broker
//The PoP token will be bound to this user / machine and to `GET https://www.contoso.com/tranfers` (the query params are not bound)
//the nonce is a requirement in this case and needs to be acquired from the resource before using this api
// Server nonce is required
string nonce = "nonce";
//HttpMethod is optional
HttpMethod method = HttpMethod.Get;
//Request URI
Uri requestUri = new Uri("https://www.contoso.com/tranfers?user=me");
var pca = PublicClientApplicationBuilder.Create(CLIENT_ID)
.WithExperimentalFeatures() // Currently POP is marked as an experimental feature
.WithBrokerPreview() //Enables the use of broker on public clients only.
.Build();
//Interactive Request
AuthenticationResult result = await pca
.AcquireTokenInteractive(new[] { "scope"})
.WithProofOfPossession(nonce, method, requestUri)
.ExecuteAsync()
.ConfigureAwait(false);
//The PoP token will be available on the AuthenticationResult returned form the acquireToken call
result.AccessToken;
//To create the auth header
var authHeader = new AuthenticationHeaderValue(result.TokenType, result.AccessToken);
//Silent Request
var accounts = await pca.GetAccountsAsync().ConfigureAwait(false);
var result = await pca.AcquireTokenSilent(new[] { "scope"}, accounts.FirstOrDefault())
.WithProofOfPossession(nonce, method, requestUri)
.ExecuteAsync()
.ConfigureAwait(false);
- Home
- Why use MSAL.NET
- Is MSAL.NET right for me
- Scenarios
- Register your app with AAD
- Client applications
- Acquiring tokens
- MSAL samples
- Known Issues
- AcquireTokenInteractive
- WAM - the Windows broker
- .NET Core
- Maui Docs
- Custom Browser
- Applying an AAD B2C policy
- Integrated Windows Authentication for domain or AAD joined machines
- Username / Password
- Device Code Flow for devices without a Web browser
- ADFS support
- Acquiring a token for the app
- Acquiring a token on behalf of a user in Web APIs
- Acquiring a token by authorization code in Web Apps
- High Availability
- Token cache serialization
- Logging
- Exceptions in MSAL
- Provide your own Httpclient and proxy
- Extensibility Points
- Clearing the cache
- Client Credentials Multi-Tenant guidance
- Performance perspectives
- Differences between ADAL.NET and MSAL.NET Apps
- PowerShell support
- Testing apps that use MSAL
- Experimental Features
- Proof of Possession (PoP) tokens
- Using in Azure functions
- Extract info from WWW-Authenticate headers
- SPA Authorization Code