-
Notifications
You must be signed in to change notification settings - Fork 218
calling graph
Jean-Marc Prieur edited this page Nov 18, 2021
·
1 revision
When you want to call Microsoft.Graph from your web app or web API, you need to:
- specify AddMicrosoftGraph in the startup.cs
- inject GraphServiceClient in the controller, or Razor page or Blazor page.
When you call AddMicrosoftGraph, you specify (by configuration or programmatically) the scopes to request initially. You can request more scopes when using a GraphServiceClient query, and you can specify that the query needed app permissions (instead of delegated permissions), or be for a specific tenant.
specify the delegated scopes to use by using .WithScopes(string[])
after the Request()
. For instance:
var users = await _graphServiceClient.Users
.Request()
.WithScopes("User.Read.All")
.GetAsync();
NumberOfUsers = messages.Count;
(that is https://graph.microsoft.com/.default) by using .WithAppOnly()
after the Request()
. For instance:
var apps = await _graphServiceClient.Applications
.Request()
.WithAppOnly()
.GetAsync();
NumberOfApps = apps.Count;
This later case requires the admin to have consented to these app-only permissions
// Apps in a specific tenant
var apps = await _graphServiceClient.Applications
.Request()
.WithAppOnly(true, tenantId)
.GetAsync();
// messages for signed-in user in a specific tenant
var messages = await _graphServiceClient.Me.Messages
.Request()
.WithAppOnly(false, tenantId)
.GetAsync();
- Home
- Why use Microsoft Identity Web?
- Web apps
- Web APIs
- Using certificates
- Minimal support for .NET FW Classic
- Logging
- Azure AD B2C limitations
- Samples
- Web apps
- Web app samples
- Web app template
- Call an API from a web app
- Managing incremental consent and conditional access
- Web app troubleshooting
- Deploy to App Services Linux containers or with proxies
- SameSite cookies
- Hybrid SPA
- Web APIs
- Web API samples
- Web API template
- Call an API from a web API
- Token Decryption
- Web API troubleshooting
- web API protected by ACLs instead of app roles
- gRPC apps
- Azure Functions
- Long running processes in web APIs
- Authorization policies
- Generic API
- Customization
- Logging
- Calling graph with specific scopes/tenant
- Multiple Authentication Schemes
- Utility classes
- Setting FIC+MSI
- Mixing web app and web API
- Deploying to Azure App Services
- Azure AD B2C issuer claim support
- Performance
- specify Microsoft Graph scopes and app-permissions
- Integrate with Azure App Services authentication
- Ajax calls and incremental consent and conditional access
- Back channel proxys
- Client capabilities