microsoft-identity-web
microsoft-identity-web copied to clipboard
[Feature Request] Support for simple usage of TokenAcquisition
Is your feature request related to a problem? Please describe. I want to be able to use ITokenAcquisition in an unauthenticated host (for example a queue triggered azure function) with minimal configuration.
Currently i need to have the following code in my startup:
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(
options => { ... }, // JwtBearerOptions
options => { ... } // MicrosoftIdentityOptions
).EnableTokenAcquisitionToCallDownstreamApi(
options => { ... } // ConfidentialClientApplicationOptions
).AddInMemoryTokenCaches();
This is misleading as it seems i'm adding authentication where it is only there so that it can configure the internal MergedOptions
.
Describe the solution you'd like I want to be able to register the ITokenAcquisition service with minimal method calls and not confusion with authentication:
services.AddTokenAcquisition(
JwtBearerDefaults.AuthenticationScheme // default authentication scheme
options => { ... }, // MicrosoftIdentityOptions
options => { ... } // ConfidentialClientApplicationOptions
).AddInMemoryTokenCaches();
This would internally do what AddMicrosoftIdentityWebApiImplementation
and CallsWebApiImplementation
do.
Describe alternatives you've considered
Current solution with AddAuthentication
works but is misleading and may register services that a not required.
Additional context Add any other context or screenshots about the feature request here.
@qetza this is a nice proposal, but we had to get our API approved from ASP.NET Core team, so I don't think we have much flexibility here. Will add it to our considerations for next major version. We also need to pass in the JwtBearerOptions as well. You should be able to write an extension method, if you need help, let us know.
I'm facing the same problem and did not manage to write an extension method like suggested that does not depend on calling AddAuthentication. @jennyf19 any help?
@qetza @aKzenT : we are working on providing an experience to do that in our next major version of Microsoft.Identity.Web. For a preview see how this would work from a daemon app: https://github.com/AzureAD/microsoft-identity-web/blob/rel/v2/tests/daemon-app/Daemon-app/Program.cs
Disclaimer: things might change a bit.
@qetza @aKzenT In rel/v2 (Microsoft.Identity.Web 2.x, you can now add token acquisition directly and this works for ASP.NET core, ASP.NET MVC and daemon scenarios. https://github.com/AzureAD/microsoft-identity-web/wiki/v2.0