Git Product home page Git Product logo

dotnet-aad-query-sample's Introduction

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
csharp
Microsoft Graph
Microsoft identity platform
id displayName
Licantrop0
Luca Spolidoro
ms-graph
dotnet-core
windows-wpf

Advanced Query Capabilities for Directory Objects with .NET SDK

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.

Getting Started

1. Register your application

Use the Microsoft Application Registration Portal to register your application with the Microsoft Graph APIs. Application Registration Note: Make sure to set the right Redirect URI for .NET Core apps: http://localhost.

2. Set the Permissions

Add the delegated permissions for Directory.Read.All. Api Permissions

3. 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:

  1. Open the Developer Command Prompt under dotnet-aad-query-sample\MSGraphSamples.WPF\ directory
  2. type dotnet user-secrets set "clientId" "<YOUR CLIENT ID>"

Build & Run

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.

Using the app

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: 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 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.

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. 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.

dotnet-aad-query-sample's People

Contributors

jasonjoh avatar licantrop0 avatar

Watchers

 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.