Git Product home page Git Product logo

dotnet-aad-query-sample's Introduction

uid description page_type createdDate languages technologies authors products extensions codeUrl zipUrl
dotnet-aad-query-sample
This sample demonstrates a .NET Desktop (WPF) application showcasing advanced Microsoft Graph Query Capabilities for Directory Objects with .NET
sample
09/22/2020 00:00:00 AM
csharp
Microsoft Graph
Microsoft identity platform
id displayName
Licantrop0
Luca Spolidoro
ms-graph
dotnet-core
windows-wpf
contentType technologies createdDate
samples
Microsoft Graph
Microsoft identity platform
09/22/2020

Explore advanced Microsoft Graph Query Capabilities for Directory Objects (AAD) with .NET SDK

Overview

This sample helps you explore the Microsoft Graph's new query capabilities of the identity APIs using the Microsoft Graph .NET Client Library v5 to query Azure AD. The main code is in AsyncEnumerableGraphDataService.cs file where, for every request:

  • The required $count=true QueryString parameter is added
  • The required ConsistencyLevel=eventual header is added
  • The request URL is extracted and displayed in the UI
  • The results are converted to an IAsyncEnumerable using the ToAsyncEnumerable extension method for an easier pagination.

Prerequisites

Registration

Step 1: Register your application

Use the Microsoft Application Registration Portal to register your application with the Microsoft Graph APIs.
Click New Registration.

Application Registration Note: Make sure to set the right Redirect URI (http://localhost) and application type is Public client/native (mobile & desktop).

Step 2: Set the MS Graph permissions

Add the delegated permissions for Directory.Read.All, and grant admin consent.
We advise you to register and use this sample on a Dev/Test tenant and not on your production tenant.

Api Permissions

Setup

Step 1: Clone or download this repository

From your shell or command line:

git clone https://github.com/microsoftgraph/dotnet-aad-query-sample.git

or download and extract the repository .zip file.

Step 2: Configure the ClientId using the Secret Manager

This application use the .NET Core Secret Manager to store the ClientId.
To add the ClientId created on step 1 of registration:

  1. Open a Developer Command Prompt or an Integrated Terminal and locate the dotnet-aad-query-sample\MSGraphSamples.WPF\ directory.
  2. Type dotnet user-secrets set "clientId" "<YOUR CLIENT ID>"

Run the sample

On Visual Studio

Press F5. This will restore the missing nuget packages, build the solution and run the project.

On Visual Studio Code

Shortly after you open the project folder in VS Code, a prompt by C# extension will appear on bottom right corner:
Required assets to build and debug are missing from 'dotnet-aad-query-sample'. Add them?.
Select Yes and a .vscode folder will be created in the project root folder.

Once this is done, open an integrated terminal in VS Code, then type:

    cd MSGraphSamples.WPF
    dotnet build
    dotnet run

Using the app

If everything was configured correctly, you should be able to see the login prompt opening in a web browser.
The auth token will be cached in a file for the subsequent runs.
You can query your tenant by typing the arguments of the standard OData $select, $filter, $orderBy, $search clauses in the relative text boxes.
In the screenshot below you can see the $search operator in action:

Screenshot of the App

  • 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 Message box.

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.

Code Architecture

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, using .NET Community Toolkit as MVVM framework.
Dependency Injection is implemented using Microsoft.Extensions.DependencyInjection, supporting design-time data.
Nullable and Code Analysis are enabled to enforce code quality.

dotnet-aad-query-sample's People

Contributors

licantrop0 avatar kalyankrishna1 avatar idg-sam avatar derisen avatar shama-k avatar baywet avatar jasonjoh avatar lauragra avatar dependabot[bot] avatar microsoft-github-policy-service[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.