# Tokens

{% embed url="https://www.xintra.org/blog/tokens-in-entra-id-guide" %}

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FYfTPjghfq4PLf2BScQi5%2Fimage.png?alt=media&#x26;token=e4f8ccd8-cf38-4e2f-a148-37d150ef9ffb" alt=""><figcaption></figcaption></figure>

### ID Tokens

* These tokens are valid for 1 hour and prove authentication (that a user has authenticated to a resource/application). The token contains information including verification details around who the user is.&#x20;
* ID tokens differ from [access tokens](https://learn.microsoft.com/en-us/entra/identity-platform/access-tokens), which serve as proof of authorization. Confidential clients should validate ID tokens. You shouldn't use an ID token to call an API.
* Can be used for authentication, but typically not used for that.

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FWnSQouxwk3APSmyHVhhi%2Fimage.png?alt=media&#x26;token=0cb4b2b9-034c-4e59-b838-5a8648ced6e6" alt=""><figcaption><p>ID Token Displayed</p></figcaption></figure>

{% embed url="https://learn.microsoft.com/en-us/entra/identity-platform/id-tokens" %}

### Access Tokens

* Valid for 1 hour, these tokens grant access to resources and are used for authorization
* These tokens embed information around who the user is and what specific resource the access is intended for. As you can see from the decoded access token below – the token has the scope [graph.microsoft.com](https://graph.microsoft.com/) via the client (application) Microsoft Office.
* CAN BE STOLEN

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2Fn61m6t5rKWX8FLJOTTYf%2Fimage.png?alt=media&#x26;token=5d5581fe-a14f-49f3-b0b5-2919428d584e" alt=""><figcaption><p>Access Token Decoded</p></figcaption></figure>

### Refresh Tokens (An Attacker’s Buffet)

* Refresh tokens are a type of bearer token that can be redeemed by an application to fetch a new set of “bearer tokens”. Since access tokens have a lifetime of 1 hour, this is where the utility of a refresh token comes in for the attacker. These tokens can be used continually within the lifetime of 90 days to obtain new access tokens. Given this power, refresh tokens are typically the primary target for attackers as it grants them up to 90 days of continual access to a specific resource / application.

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FSUUzmzWrb0t8PRLxhb3r%2Fimage.png?alt=media&#x26;token=baa52902-a3c5-4259-aa3c-44c05de51a32" alt=""><figcaption></figcaption></figure>

### Primary Refresh Tokens

Valid for 14 days, these refresh tokens are used for single sign-in (SSO) across applications used on the device and contain two additional details embedded in them:

* **Device ID:** This field identifies the device where the PRT resides on
* _**Session Key:**_ Acts as a proof of possession when the PRT obtains tokens for other applications
* **Conditional Access policies** are not evaluated when PRTs are issued. Therefore, if an attacker steals a PRT, it will automatically satisfy device-based conditional access policies.

\
