Token Binding is a mechanism that ensures the device requesting access to resources is bound to the access token, which grants access to those resources. By combining this mechanism with the Conditional Access session control ‘Token Protection’, we can enforce strong security requirements to prevent the use of stolen access tokens in Microsoft Entra.
Unfortunately, Token Binding requires the application requesting the token to support it, as the application must be able to interact with the necessary system components to use a device-bound token, such as the Primary Refresh Token on Entra-registered devices.
In this article, I am going to focus on Microsoft Graph PowerShell, demonstrating how you can enforce Token Protection when connecting to Microsoft Graph PowerShell, preventing its use on devices which do not belong to said user. The minimises the risk of access tokens being stolen from PowerShell sessions left active on other devices.
Page Contents
How does token binding work?
Token binding provides enhanced security in authentication by creating a cryptographic link between a token and the specific device that requested it. This helps prevent token theft and replay attacks, where an attacker steals a token and tries to re-use it on their own device.
In Microsoft’s world, when a user registers their Windows device to Microsoft Entra ID, their Identity is bound to the device, whether that device be Entra Joined, Entra Hybrid Joined or Entra Registered. When this registration takes place, a PRT (or Primary Refresh Token) is issued to the device containing the Device key (which is used to identify the device) and a Session key (which acts as the proof of possession when requesting an access token), creating that binding.
The important bit is the Session key, the Session key at high-level is used to sign requests to Microsoft Entra ID, proving that the identity is bound to the device for Microsoft Entra to validate it and provide access to protected resources. If they Session key in stolen, an attacker could in theory, evade Token Protection mechanisms.
So it is important to keep the Session key safe, and to protect it, it is stored on the devices Trusted Platform Module (a purpose made security chip), which is a hardware security module designed for protecting secrets. If your device does not have a TPM chip, it is stored using software encryption in the file systems as a protected blob of data, which is arguably less secure. This is where admins can drastically improve security by implementing device compliance mechanisms in services like Microsoft Intune to require only devices with a functioning TPM chip.
At a simplified level, the below diagram represents the flow for accessing protected resources using Token Binding:
Step 1: When a device registers with Microsoft Entra, the system generates essential cryptographic key pairs which are stored on the device TPM chip:
- Device Key – Used to uniquely identify the device
- Transport Key – Used to encrypt the Proof of Possession (PoP) or Session key
Step 2: When an application wants to access protected resources, it sends an authorisation request to the identity provider. The request header includes:
- The device’s public key
- A signature created with the private key (proof of possession)
Step 3: The identity provider verifies that the sender possesses the private key corresponding to the public key, then responds with an access token bound by the public key.
Step 4: With this, the application generates a new token, sending it to the resource server containing:
- The public key
- A signature created by the corresponding private key
- A payload for the API request
Step 5: Before granting access, the system verifies that the DPoP (Demonstration of Proof of Possession) proof matches the public key included in the request.
Step 6: Once verification succeeds, the protected resources are returned to the application.
The problem with Bearer tokens
What if I’m not using Token Protection? Well, let’s think about the standard OAuth flow that’s seen all around us. When your client application goes through the dance of requesting access, it gets its access token, and off it goes to access its resources. Simple enough…
Here’s where things get interesting (and by that, I mean potentially problematic). That access token you’ve just obtained? It’s called a “bearer token.” The problem is in the name, whoever bears this token can use it. No questions asked. No additional verification.
Liken it to you walking down the street and you find someone’s house key on the ground. With that key in your hand, you can walk right up to their front door and let yourself in. The lock doesn’t care who you are, it just cares that you have the right key.
This is exactly the security problem we’re dealing with here. If someone manages to get their hands on your access token, they’ve essentially got your house key. They can walk right into your protected resources and help themselves to whatever they can access, at least until that token decides to expire.
But, lets say you installed a finger print reader on your front door, now even if the attacker found the key, they wouldn’t be able to bypass the biometric security bound to the house owner, in theory.
Token protection in Conditional Access
Let’s now look at how token binding can be enforced for accessing resources protected by Microsoft Entra, using the Token Protection in Conditional Access.
When administrators enable “Require token protection for sign-in sessions” within the Session Controls section of Conditional Access policies, any sessions attempting to access resources covered by that policy must demonstrate cryptographic binding to the original device through proof-of-possession. This proof-of-possession mandates that the client application must demonstrate possession of the corresponding private key stored on the device. Should a malicious actor successfully exfiltrate a Refresh Token from a compromised user device and attempt to utilise it from their own device, the proof-of-possession validation via Conditional Access will fail due to the absence of the private key, resulting in the policy blocking the access request.
To enable Token Protection in Conditional Access, simply create a new policy with the Token Protection session control enabled, targeting specific apps or resources, like so:
Applications that support Token Protection
Unfortunately not all applications support the use of Token Protection in Conditional Access, which is a shame considering how powerful the feature is. Never the less, below is a list of applications that currently support Token Protection:
- OneDrive sync client version 22.217 or newer
- Teams native client version 1.6.00.1331 or newer
- Power BI desktop version 2.117.841.0 (May 2023) or newer
- Exchange PowerShell module version 3.7.0 or newer
- Microsoft Graph PowerShell version 2.0.0 or newer with EnableLoginByWAM option
- Visual Studio 2022 or newer when using the ‘Windows authentication broker’ Sign-in option
- Windows App version 2.0.379.0 or newer
As Windows and other apps modernise, I hope this feature is expanded out, with the goal to support all Microsoft own public applications.
Enforce Token Protection for Microsoft Graph PowerShell
To utilise Token Binding and hence enforce Token Protection while accessing resources with Microsoft Graph PowerShell, you must enable WAM (Web Account Manager) support.
Web Account Manager (WAM): WAM is the default token broker on Windows 10 or newer devices. WAM also provides a plugin framework that identity providers can build on and enable SSO to their applications relying on that identity provider.
Enabling WAM support will allow the module to launch the ‘WAM popup’ or interactive login experience. If your device contains a PRT for the desired account, the account will show as logged in and allow you to single sign on. If the account is not in the list, then you will be prompted to sign in interactively. In this scenario, you will be blocked and presented with the following message.
To solve this problem, you will need to add and register your device to your target account. The easiest way of doing this, is to follow these steps:
- In your Windows search bar, type Email & Accounts.
- Click Add a workplace or school account.
- Follow the wizard to sign in.
Doing this will add your account to Windows and allow your device to obtain a Primary Refresh Token, which can be used by the Web Account Manager to sign you in to Microsoft Graph PowerShell. This time, when you now connect you will see your target account available in the interactive login box.
You should now have a successful connection!
In the event, someone tried to login without WAM enabled, with Token Protection enforced, they will get the following message:


Hey, thanks! I cannot remember but for what was demonstrated in the blog it doesn’t matter 🙂