Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Offer a message handler approach with ITokenAcquisition #1087

Closed
rellis-of-rhindleton opened this issue Mar 25, 2021 · 5 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@rellis-of-rhindleton
Copy link

MSAL Angular uses a "protected resource map" approach to handle multiple downstream APIs. With the ITokenAcquisition service you're just a few steps away from being able to do the same thing.

I wanted to use the Http message handler approach in a project and set up a couple of (very) simple classes to handle it. Passing it along. If it doesn't fit the needs of the library, no worries.

Stripped-down example:
https://github.com/rellis-of-rhindleton/token-acquisition-handler

(That example uses a custom Graph client, I know that's redundant but I wanted a working example.)

@rellis-of-rhindleton rellis-of-rhindleton added the enhancement New feature or request label Mar 25, 2021
@jmprieur
Copy link
Collaborator

jmprieur commented May 6, 2021

@rellis-of-rhindleton : what about IDownstreamWebAPI? doesn't it do something similar?

@rellis-of-rhindleton
Copy link
Author

rellis-of-rhindleton commented May 6, 2021

I want to use the typical/idiomatic HttpClient configuration approach in Startup.cs. IDownstreamWebAPI seems to not allow that sort of customization. I may have missed something, though.

Using ITokenAcquisition it’s easy to build a simple handler that gets a token as needed for a downstream resource, which can be plugged in to the configuration of an HttpClient along with whatever other handlers might be needed. It’s easy to do myself. I just figured the project is very close to it already and maybe could do something similar out of the box.

services.AddTokenAcquisitionHandler(
    Configuration.GetSection("DownstreamApiA"),
    Configuration.GetSection("DownstreamApiB")
);

services.AddHttpClient<DownstreamApiA>(client =>
    {
        // client options
    })
    .AddHttpMessageHandler<TokenAcquisitionHandler>()
    .AddHttpMessageHandler<SomeOtherHandler>();

@jmprieur
Copy link
Collaborator

jmprieur commented May 7, 2021

@rellis-of-rhindleton. I understand better. Thanks for clarifying.
So I think it's a duplicate of #1131

BTW, in https://github.com/rellis-of-rhindleton/token-acquisition-handler#appsettingsjson-or-other-configuration, I don't understand why would would want you express which flow to use? Microsoft.Identity.Web abstracts this out for you, you don't need to know if this is OBO, Auth Code Flow, silent flow, refresh, etc ... you only have to choose between a user-flow or an app-only-flow.

@jmprieur jmprieur added the duplicate This issue or pull request already exists label May 7, 2021
@rellis-of-rhindleton
Copy link
Author

It does seem to be the same, yes.

I’m not sure I understand the list of options you posted in your comment there... I would only suggest that the handler be available for use without too much abstraction surrounding it. I’m a fan of convenience classes when appropriate, but the need to plug in multiple handlers and control HttpClient configuration seems to come up a lot.

As far as specifying the flow — that was just my attempt at explicit configuration, and not really necessary, you can ignore it. My first draft chose app-or-user automatically by checking the scope for “/.default” (and throwing an exception if there was more than one). Changed it to be more explicit because of my personal circumstances — I’ve been trying to teach OAuth to a lot of people lately and it’s complicated.

@jennyf19
Copy link
Collaborator

This was included in 1.15.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants