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

[External - Prism.DryIoc.Extensions] Authenticationhandler can only work on the last registered item??? #3

Closed
dorisoy opened this issue Aug 6, 2020 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@dorisoy
Copy link

dorisoy commented Aug 6, 2020

I have defined three interfaces, as follows:

[Policy("TransientHttpError")]
[WebApi(GlobalSettings.BaseEndpoint + "api/v3/dcms/news", isAutoRegistrable: false), Trace]
public interface INewsApi
{
[Get("/topnews/0/6")]
[Headers("Authorization: Bearer")]
Task<APIResult<IList>> GetTopNewsAsync([CacheKey] int storeId, CancellationToken calToken = default);
}

[WebApi(GlobalSettings.BaseEndpoint + "api/v3/dcms/auth/user", isAutoRegistrable: false), Trace]
public interface IAuthorizationApi
{
[Get("/bearer/{store}/{userid}")]
[Headers("Authorization: Bearer")]
Task AuthBearerAsync(int store, int userid);
}

Register as follows in Startup : PrismStartup

//(1)
services.UseApizrFor(ob => ob
.WithHttpTracing(HttpTracer.HttpMessageParts.All)
.WithCacheHandler()
.WithAuthenticationHandler(settings => settings.Token, OnRefreshToken));

//(2)
services.UseApizrFor(ob => ob
.WithHttpTracing(HttpTracer.HttpMessageParts.All)
.WithCacheHandler()
.WithAuthenticationHandler(settings => settings.Token, OnRefreshToken));

Test case as follows:

//Test
var newsServie = Shiny.ShinyHost.Resolve<IApizrManager>();
var news = await newsServie.ExecuteAsync((ct, api) => api.GetTopNewsAsync(Settings.StoreId, ct), CancellationToken.None);
// 401 Unauthorized!!

var _httpBinManager = Shiny.ShinyHost.Resolve<IApizrManager>();
var response = await _httpBinManager?.ExecuteAsync(api => api.AuthBearerAsync(Settings.StoreId, Settings.UserId)) as HttpResponseMessage;
// 200 Ok!!

When I change the order of 1 and 2, the 1 available request succeeds and 2 fails

//Test
var newsServie = Shiny.ShinyHost.Resolve<IApizrManager>();
var news = await newsServie.ExecuteAsync((ct, api) => api.GetTopNewsAsync(Settings.StoreId, ct), CancellationToken.None);
// 200 Ok!!

var _httpBinManager = Shiny.ShinyHost.Resolve<IApizrManager>();
var response = await _httpBinManager?.ExecuteAsync(api => api.AuthBearerAsync(Settings.StoreId, Settings.UserId)) as HttpResponseMessage;
// 401 Unauthorized!!

????? I need your help. Thank you very much!!!

@JeremyBP
Copy link
Contributor

JeremyBP commented Aug 6, 2020

Hi @dorisoy ,

Actually, I noticed that behavior yesterday on my side.
Thank you for reporting it.
I have to fix that thing.

Expect a 1.5.1 nuget update probably tomorrow.

Regards

@JeremyBP JeremyBP added the bug Something isn't working label Aug 7, 2020
@JeremyBP JeremyBP self-assigned this Aug 7, 2020
@JeremyBP
Copy link
Contributor

JeremyBP commented Aug 7, 2020

Ok I investigated.

First I tried to reproduce this bug in the mobile sample with two authenticated api interfaces.
Same config as yours, same error 401 as yours.
Then I tried with the console sample with all the same config but not the same result, as it returned me a success 200 for both api calls...?!!!

I found out that I was using MS DI with the console sample and DryIoc with the mobile one.
And guess what? Replacing DryIoc by MS DI in the mobile sample fixed the problem.

Actually, we're still talking about the same problem wich is #1, wich still comes from #124 on Prism.DryIoc.Extensions

Apizr makes use of AddHttpClient and AddTypedClient service collection official extensions wich register multiple implementation type for a same service type. This is not yet available using Prism.DryIoc.Extensions. That's what I'm talking about on my Readme notes.

Personally, my workaround is to use Prism.Microsoft.DependencyInjection.Extensions instead of Prism.DryIoc.Extensions.

Actually, waiting for this to be fixed and released on Nuget for DryIoc, you'd better download the Prism.Container.Extensions project as I did, fixe the MS DI NavigationService issue like I did in this not yet approved PR (only one line of code), and refrence this MS DI project directly into yours.

You'll get all working as excpected so far.

@JeremyBP JeremyBP changed the title Authenticationhandler can only work on the last registered item??? [External - Prism.DryIoc.Extensions] Authenticationhandler can only work on the last registered item??? Aug 7, 2020
@dorisoy
Copy link
Author

dorisoy commented Aug 10, 2020

@JeremyBP
Well, as you said, Thank you for your contribution to this project and I will adopt the solution you suggest。

@JeremyBP
Copy link
Contributor

JeremyBP commented Dec 8, 2020

Dan just pushed its container extensions packages on NuGet with multiple instance registration/resolution feature, witch finally fix this. Please make sur to update to at least v8.0.48

@JeremyBP JeremyBP closed this as completed Dec 8, 2020
@dorisoy
Copy link
Author

dorisoy commented Dec 8, 2020

Dan just pushed its container extensions packages on NuGet with multiple instance registration/resolution feature, witch finally fix this. Please make sur to update to at least v8.0.48

@JeremyBP Thank you for sharing everything for open source !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants