uid | title | description | page_type | createdDate | languages | technologies | authors | products | codeUrl | zipUrl | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
dotnet-aad-query-sample |
Microsoft Graph Directory Objects Advanced Queries with .NET SDK |
Learn how to use .NET Graph SDK to query Directory Objects |
sample |
09/22/2020 00:00:00 AM |
|
|
|
|
This sample helps you explore the Microsoft Graph's new query capabilities of the Identity APIs using the Microsoft Graph SDK to query AAD.
The main code is in GraphDataService.cs file, where every request pass trough AddAdvancedOptions
function adding the required $count=true
QueryString parameter and ConsistencyLevel=eventual
header.
Use the Microsoft Application Registration Portal to register your application with the Microsoft Graph APIs.
Note: Make sure to set the right Redirect URI for .NET Core apps:
http://localhost
.
Add the delegated permissions for Directory.Read.All
.
This application use the .NET Core Secret Manager to store the ClientId. To add the ClientId created on step 1:
- Open the Developer Command Prompt under
dotnet-aad-query-sample\MSGraphSamples.WPF\
directory - type
dotnet user-secrets set "clientId" "<YOUR CLIENT ID>"
If everything was configured correctly, you should be able to run the application, and see the first login prompt. The auth token will be cached for the subsequent runs.
You can query your tenant using the standard OData $filter
, $search
, $orderBy
, $select
clauses in the relative textboxes.
In the screenshot below you can see the $search operator in action:
If you double click on a row, a default drill-down will happen (for example by showing the list of transitive groups a user is part of). If you click on a header, the results will be sorted by that column. Note: not all columns are supported and you may receive an error. If any query error happen, it will displayed with a MessageBox. The generated URL will appear in the readonly Url textbox. You can click the Graph Explorer button to open the current query in Graph Explorer.
This app provides a good starting point for enterprise desktop applications that connects to Microsoft Graph.
The implementation is a classic WPF MVVM app with Views, ViewModels and Services. ICommand and INotifyPropertyChanged are manually implemented.
Dependency Injection is implemented using Microsoft.Extensions.DependencyInjection
, supporting design-time data.
Nullable and Code Analysis are enabled to enforce code quality.