Skip to content

Commit c39d3a8

Browse files
authored
Merge pull request #190173 from kengaderdus/resolve-GHI-84610-and-88760
[Azure AD B2C] Update code snippets using out of repo code reference
2 parents 9c2271a + bb61845 commit c39d3a8

File tree

2 files changed

+9
-38
lines changed

2 files changed

+9
-38
lines changed

.openpublishing.publish.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@
807807
"branch": "master",
808808
"branch_mapping": {}
809809
},
810+
{
811+
"path_to_root": "ms-identity-dotnetcore-b2c-account-management",
812+
"url": "https://github.com/Azure-Samples/ms-identity-dotnetcore-b2c-account-management",
813+
"branch": "master",
814+
"branch_mapping": {}
815+
},
810816
{
811817
"path_to_root": "msdocs-python-flask-webapp-quickstart",
812818
"url": "https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart",

articles/active-directory-b2c/microsoft-graph-operations.md

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ For more information about accessing Azure AD B2C audit logs, see [Accessing Azu
167167
When you want to manage Microsoft Graph, you can either do it as the application using the application permissions, or you can use delegated permissions. For delegated permissions, either the user or an administrator consents to the permissions that the app requests. The app is delegated with the permission to act as a signed-in user when it makes calls to the target resource. Application permissions are used by apps that do not require a signed in user present and thus require application permissions. Because of this, only administrators can consent to application permissions.
168168

169169
> [!NOTE]
170-
> Delegated permissions for users signing in through user flows or custom policies cannot be used against delegated permissions for Microsoft Graph.
170+
> Delegated permissions for users signing in through user flows or custom policies cannot be used against delegated permissions for Microsoft Graph API.
171171
## Code sample: How to programmatically manage user accounts
172172

173173
This code sample is a .NET Core console application that uses the [Microsoft Graph SDK](/graph/sdks/sdks-overview) to interact with Microsoft Graph API. Its code demonstrates how to call the API to programmatically manage users in an Azure AD B2C tenant.
@@ -212,46 +212,11 @@ The `RunAsync` method in the _Program.cs_ file:
212212
1. Initializes the auth provider using [OAuth 2.0 client credentials grant](../active-directory/develop/v2-oauth2-client-creds-grant-flow.md) flow. With the client credentials grant flow, the app is able to get an access token to call the Microsoft Graph API.
213213
1. Sets up the Microsoft Graph service client with the auth provider:
214214

215-
```csharp
216-
// Read application settings from appsettings.json (tenant ID, app ID, client secret, etc.)
217-
AppSettings config = AppSettingsFile.ReadFromJsonFile();
218-
219-
// Initialize the client credential auth provider
220-
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
221-
.Create(config.AppId)
222-
.WithTenantId(config.TenantId)
223-
.WithClientSecret(config.ClientSecret)
224-
.Build();
225-
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
226-
227-
// Set up the Microsoft Graph service client with client credentials
228-
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
229-
```
215+
:::code language="csharp" source="~/ms-identity-dotnetcore-b2c-account-management/src/Program.cs" id="ms_docref_set_auth_provider":::
230216

231217
The initialized *GraphServiceClient* is then used in _UserService.cs_ to perform the user management operations. For example, getting a list of the user accounts in the tenant:
232218

233-
```csharp
234-
public static async Task ListUsers(GraphServiceClient graphClient)
235-
{
236-
Console.WriteLine("Getting list of users...");
237-
238-
// Get all users (one page)
239-
var result = await graphClient.Users
240-
.Request()
241-
.Select(e => new
242-
{
243-
e.DisplayName,
244-
e.Id,
245-
e.Identities
246-
})
247-
.GetAsync();
248-
249-
foreach (var user in result.CurrentPage)
250-
{
251-
Console.WriteLine(JsonConvert.SerializeObject(user));
252-
}
253-
}
254-
```
219+
:::code language="csharp" source="~/ms-identity-dotnetcore-b2c-account-management/src/Services/UserService.cs" id="ms_docref_get_list_of_user_accounts":::
255220

256221
[Make API calls using the Microsoft Graph SDKs](/graph/sdks/create-requests) includes information on how to read and write information from Microsoft Graph, use `$select` to control the properties returned, provide custom query parameters, and use the `$filter` and `$orderBy` query parameters.
257222

0 commit comments

Comments
 (0)