-
Notifications
You must be signed in to change notification settings - Fork 12
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
Comments
Hi @dorisoy , Actually, I noticed that behavior yesterday on my side. Expect a 1.5.1 nuget update probably tomorrow. Regards |
Ok I investigated. First I tried to reproduce this bug in the mobile sample with two authenticated api interfaces. I found out that I was using MS DI with the console sample and DryIoc with the mobile one. 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 |
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 ! |
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!!!
The text was updated successfully, but these errors were encountered: