manuel-guilbault / aspnetcore.noninteractiveoidchandlers Goto Github PK
View Code? Open in Web Editor NEWA set of DelegatingHandlers for various HttpClient non-interactive authentication scenarios using Open ID Connect.
A set of DelegatingHandlers for various HttpClient non-interactive authentication scenarios using Open ID Connect.
Hi,
Is there a way to share tokens between multiple Typed HttpClients that use the same authentication configuration?
Here's an example of my code:
void ConfigureClientCredentialsTokenHandlerOptions(ClientCredentialsTokenHandlerOptions options)
{
options.Authority = Configuration.Auth0.Authority;
options.ClientId = Configuration.Auth0.ClientId;
options.ClientSecret = Configuration.Auth0.ClientSecret;
options.Scope = "customers suppliers";
options.GrantType = Configuration.Auth0.GrantType;
options.EnableCaching = true;
}
services.AddHttpClient<ICustomerClient, CustomerClient>(
client => client.BaseAddress = new Uri(Configuration.BaseUri)
).AddOidcClientCredentials(ConfigureClientCredentialsTokenHandlerOptions);
services.AddHttpClient<ISupplierClient, SupplierClient>(
client => client.BaseAddress = new Uri(Configuration.BaseUri)
).AddOidcClientCredentials(ConfigureClientCredentialsTokenHandlerOptions);
In this case a token is fetched and cached per HttpClient. But I'm looking for a solution where the token is only fetched once.
Regards,
Jochen
When caching is not enabled, the following error occurs: An item with the same key has already been added. Key: scope
The cause is the following line:
My configuration uses:
options.ExtraTokenParameters = new Dictionary<string, string> {{"audience", Configuration.Audience}};
The issue is that the Dictionary is reused and thus the second time, keys that already part of the dictionary are added again.
The solution is to create a new dictionary based on the dictionary in the options.
Parameters = _options.ExtraTokenParameters ? new Dictionary<string, string>(_options.ExtraTokenParameters) : new Dictionary<string, string>(),
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.