AzureAD / microsoft-identity-web

Helps creating protected web apps and web APIs with Microsoft identity platform and Azure AD B2C
MIT License
670 stars 208 forks source link

[Feature Request] Keyed service GraphServiceClient #2979

Open scrocquesel-ml150 opened 4 weeks ago

scrocquesel-ml150 commented 4 weeks ago

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

MichaMican commented 2 weeks ago

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?

scrocquesel-ml150 commented 2 weeks ago

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.