You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: support/entra/entra-id/app-integration/get-signed-in-users-groups-in-access-token.md
+17-14Lines changed: 17 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,13 @@
1
1
---
2
-
title: Get signed in user groups from groups overage claim
3
-
description: Provides a sample project to introduce how to to get signed in user groups when groups overage claim is displayed in access tokens.
2
+
title: Get signed in user groups list from groups overage claim
3
+
description: Provides a sample project to introduce how to get signed in user groups list when groups overage claim is displayed in access tokens.
4
+
ms.topic: How-To
4
5
ms.reviewer: v-weizhu
5
6
ms.service: entra-id
6
-
ms.date: 03/07/2025
7
+
ms.date: 03/10/2025
7
8
ms.custom: sap:Developing or Registering apps with Microsoft identity platform
8
9
---
9
-
# How to get signed in user groups when groups overage claim is displayed in access tokens
10
+
# How to get signed in user groups list when groups overage claim is displayed in access tokens
10
11
11
12
When you configure the `groups` claim in an access token for your application, Microsoft Entra ID has a maximum number of groups that can be returned in an access token. When the limit is exceeded, Azure provides a groups overage claim which is a URL that can be used to get the full groups list for the currently signed in user. This URL uses the Microsoft Graph endpoint. For more information about the `groups` claim, see [Access tokens in the Microsoft identity platform](/entra/identity-platform/access-tokens).
12
13
@@ -101,9 +102,10 @@ Download the sample project [MSAL.Net_GroupOveragesClaim](https://github.com/Ray
101
102
102
103
## About the code
103
104
104
-
### Get_GroupsOverageClaimURL
105
+
### Get_GroupsOverageClaimURL method
106
+
107
+
The sample project uses MSAL.NET (`Microsoft.Identity.Client`) to authenticate users and obtain access tokens. `System.Net.Http` is used for the HTTP client and Microsoft.Graph SDK is used for the graph client. To parse the JSON file, `System.Text.Json` is used. To get the claims from the token, `System.IdentityModel.Tokens.Jwt` is used. The `JwtSecurityToken` provider is used to retrieve the groups overage claim in the token.
105
108
106
-
The sample application uses MSAL.NET (`Microsoft.Identity.Client`) to authenticate users and obtain access tokens. `System.Net.Http` is used for the HTTP client and Microsoft.Graph SDK is used for the graph client. To parse the JSON file, `System.Text.Json` is used. To get the claims from the token, `System.IdentityModel.Tokens.Jwt` is used. The `JwtSecurityToken` provider is used to retrieve the groups overage claim in the token.
107
109
If the token contains the claims `claim_names` and `claim_sources`, then it indicates the presence of a group overages claim within the token. In this case, use the user ID (oid) and the two claims to construct the URL for the groups list and output the original value in the console windows. If either of the two claim values doesn't exist, the `try/catch` block will handle the error and return a `string.empty` value. This indicates that there is no groups overage claim in the token.
108
110
109
111
```csharp
@@ -146,9 +148,10 @@ If the token contains the claims `claim_names` and `claim_sources`, then it indi
146
148
}
147
149
```
148
150
149
-
### Program.cs
151
+
### Program.cs file
150
152
151
153
In this file, there is a public client application configuration for user sign-in and getting access tokens, and a confidential client application for application sign-in and getting access tokens (the client credentials grant flow). `ManualTokenProvider` is used for the Graph Service Client to pass an access token to the service instead of having Graph obtain it.
154
+
152
155
There is also an *appsettings.json* file and a class to store those settings (*AzureConfig.cs*) at runtime. The public static property `AzureSettings` retrieves settings from the configuration file using a configuration builder, similar to ASP.NET Core applications. This feature must be added as it's not native to a console application.
For the `Authentication` provider for the Graph service client, the sample project uses a custom manual token provider to set the access token for the client it already obtains access tokens using MSAL.
The HTTP method has 2 parts, the method `Get_Groups_Http_Method` will call `Graph_Request_viaHTTP` to get the list of groups and then displays that list in the console window.
217
+
This `Get_Groups_HTTP_Method` method will call the `Graph_Request_viaHTTP` method to get the list of groups and then displays that list in the console window.
215
218
216
219
```csharp
217
220
/// <summary>
@@ -317,7 +320,7 @@ The HTTP method has 2 parts, the method `Get_Groups_Http_Method` will call `Grap
317
320
}
318
321
```
319
322
320
-
### Get_Groups_GraphSDK_Method in Program.cs
323
+
### Get_Groups_GraphSDK_Method
321
324
322
325
In a similar fashion, the Graph SDK has an entry method `Get_Groups_GraphSDK_Method`. This method will call `Get_GroupList_GraphSDK` to get the list of groups and then display it in the console window.
323
326
@@ -339,9 +342,9 @@ In a similar fashion, the Graph SDK has an entry method `Get_Groups_GraphSDK_Met
339
342
}
340
343
```
341
344
342
-
### Get_GroupList_GraphSDK method in Program.cs
345
+
### Get_GroupList_GraphSDK method
343
346
344
-
Determine whether to use the `me` endpoint or the `users` endpoint to get the group list. If you use the client credentials grant flow to get the access token for Microsoft Graph, use the `users` endpoint. If not (for example, a delegated flow is used for the access token), use the `users` endpoint.
347
+
This method determines whether to use the `me` endpoint or the `users` endpoint to get the group list. If you use the client credentials grant flow to get the access token for Microsoft Graph, use the `users` endpoint. If not (for example, a delegated flow is used for the access token), use the `users` endpoint. Regardless of the method used, the code will handle paging because by default, only 100 records per page will be returned. Paging is determined via the `@odata.nextLink` value. If there is a value for that property, the full URL is called for the next page of data. For more information about paging, see [Paging Microsoft Graph data in your app](/graph/paging).
345
348
346
349
```csharp
347
350
/// <summary>
@@ -415,5 +418,5 @@ Determine whether to use the `me` endpoint or the `users` endpoint to get the gr
415
418
416
419
}
417
420
```
421
+
[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)]
418
422
419
-
Regardless of the method used, the code will handle paging because by default, only 100 records per page will be returned. Paging is determined via the `@odata.nextLink` value. If there is a value for that property, the full URL is called for the next page of data. For more information about paging, see [Paging Microsoft Graph data in your app](/graph/paging).
0 commit comments