Description
I use Identity.Web/Identity.Web.MicrosoftGraph v1.2 & MS Graph SDK v3.19 in an asp core 3.1 web api application.
I use graph in AppOnly mode. This is my configuration:
services.AddAuthentication()
.AddMicrosoftIdentityWebApp(opts =>
{
opts.Instance = "https://login.microsoftonline.com/";
opts.TenantId = "B2CTenantId";
opts.ClientId = "B2CClientId";
opts.ClientSecret = "B2CClientSecret";
opts.BackchannelHttpHandler = new HttpClientHandler
{
UseProxy = true,
Proxy = new System.Net.WebProxy { Address = new System.Uri("myproxy") }
};
})
.EnableTokenAcquisitionToCallDownstreamApi(opts =>
{
opts.Instance = "https://login.microsoftonline.com/";
opts.TenantId = "B2CTenantId";
opts.ClientId = "B2CClientId";
})
.AddMicrosoftGraphAppOnly(provider => new GraphServiceClient(GraphClientFactory.Create(provider, proxy: new System.Net.WebProxy { Address = new System.Uri("myproxy") })))
.AddInMemoryTokenCaches();
The first and obvious question is: is this the correct way? I never found any examples with the simple confidential client configuration.
The second question is: why does it require AddAuthentication
? I add authentication to my app anyway, so it's not a problem for me, but still. As far as I understood, the main difference between AddApp
and AddApi
is that the former doesn't add the authentication schema, and doesn't authorize the api users. So it shouldn't require the AuthenticationBuilder
, should it?
The third question is about Instance
. Why do I need to explicitly provide it? Shouldn't https://login.microsoftonline.com/
be the obvious default? Could you at least provide it in some public constant somewhere, so that I did not need to hardcode it myself.
And the last question is about duplication. I need to explicitly provide both MicrosoftIdentityOptions
and ConfidentialClientApplicationOptions
with the same set of parameters. Why confidential client setup doesn't copy the parameters from microsoft identity? It does copy ClientSecret
, but nothing else. Why?