You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to add two instances of GraphServiceClient via calls to AddMicrosoftGraph, one for calling on-behalf-of users and another for calling as the application itself?
#3277
I want two GraphServiceClients in my application - one for calling Microsoft Graph on-behalf-of users and another for calling it as the application itself.
More concretely, my current application has two abstractions, ISystemGraphService and IDelegatedGraphService:
builder.Services.AddScoped<ISystemGraphService>(serviceProvider =>
{
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
return new GraphService(new GraphServiceClient(serviceProvider.GetRequiredService<DefaultAzureCredential>()),
httpContextAccessor, serviceProvider.GetRequiredService<IConfiguration>());
});
builder.Services.AddScoped<IDelegatedGraphService>(serviceProvider =>
{
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
var httpContext = httpContextAccessor.HttpContext ?? new DefaultHttpContext();
var tokenAcquisition = serviceProvider.GetRequiredService<ITokenAcquisition>();
return new GraphService(new GraphServiceClient(new TokenAcquisitionTokenCredential(tokenAcquisition)), httpContextAccessor, serviceProvider.GetRequiredService<IConfiguration>());
});
I don't want to create initialize the GraphServiceClients manually, but utilize the Microsoft.Identity.Web abstraction to initialize them via appsettings.json (e.g. AzureAd section).
The docs show how to use both Microsoft Graph and Microsoft Graph Beta simultaneously, but not two different instances of GraphServiceClients targeting the same Microsoft Graph API.
How can I use the Microsoft.Identity.Web to create my abstractions above?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the following code:
I want two
GraphServiceClients in my application - one for calling Microsoft Graph on-behalf-of users and another for calling it as the application itself.More concretely, my current application has two abstractions,
ISystemGraphServiceandIDelegatedGraphService:I don't want to create initialize the
GraphServiceClients manually, but utilize theMicrosoft.Identity.Webabstraction to initialize them via appsettings.json (e.g.AzureAdsection).The docs show how to use both Microsoft Graph and Microsoft Graph Beta simultaneously, but not two different instances of
GraphServiceClients targeting the same Microsoft Graph API.How can I use the
Microsoft.Identity.Webto create my abstractions above?https://learn.microsoft.com/en-us/entra/identity-platform/scenario-web-app-call-api-call-api?tabs=aspnetcore#option-1-call-microsoft-graph-with-the-sdk
Beta Was this translation helpful? Give feedback.
All reactions