microsoft-identity-web icon indicating copy to clipboard operation
microsoft-identity-web copied to clipboard

[Feature Request] Keyed service GraphServiceClient

Open scrocquesel-ml150 opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. I have an application that connect to multiple tenants. I would like to be able to retrieve a GraphServiceClient configured for a given tenant. This should be similar to serviceName for DownstreamApi

Describe the solution you'd like

services
    .Configure<MicrosoftIdentityApplicationOptions>("foo", configuration.GetSection("AzureAds:foo")
    .Configure<MicrosoftIdentityApplicationOptions>("bar", configuration.GetSection("AzureAds:bar")
    
    .AddMicrosoftGraph("foo", configuration.GetSection("Tenants:foo"))
    .AddMicrosoftGraph("bar", configuration.GetSection("Tenants:bar"));
// or
services
    .AddMicrosoftGraphs(configuration.GetSection("Tenants"))
public class MyService([FromKeyedServices("Foo")] GraphServiceClient graphClient) {}
// or more dynamic
serviceProvider.GetRequiredKeyedService<GraphServiceClient>(tenant);

Describe alternatives you've considered I tried do it myself but utility classes like GraphAuthenticationProvider and GraphClientFactory are internal.

Additional context N/A

scrocquesel-ml150 avatar Aug 14 '24 21:08 scrocquesel-ml150

You could configure your GraphServiceClients manually with TokenCredentials from Azure.Identity and then use the allready proposed KeyedService feature for dependency injection to achive this.

If i understand you correctly you basically want this beeing integrated into the Configuration wrapper - right?

MichaMican avatar Aug 23 '24 06:08 MichaMican

You could configure your GraphServiceClients manually with TokenCredentials from Azure.Identity and then use the allready proposed KeyedService feature for dependency injection to achive this.

If i understand you correctly you basically want this beeing integrated into the Configuration wrapper - right?

Yes, that's exactly that.

scrocquesel-ml150 avatar Aug 23 '24 07:08 scrocquesel-ml150