602076b669e2789aa2239eff7a53a2ac89884291
Publish NuGets / build (release) Failing after 13s
Lightweight library allowing to manage access token its lifetime with caching capability for services accounts with the oauth2 protocol
Installing Nuget
Install nuget package to your awesome project.
How to use
appsettings.json
{
"JwtTokenManager": {
"TokenEndpoint": "",
"ClientId": "",
"ClientSecret": "",
"Scopes": []
}
}
Program.cs
builder.Services.AddHttpClient();
builder.Services.AddMemoryCache(); // use the IMemoryCache provider you want
builder.Services.AddJwtTokenManager(builder.Configuration, "JwtTokenManager");
Program.cs with deeper configurations
builder.Services.AddHttpClient();
builder.Services.AddJwtTokenManager(builder.Configuration, "JwtTokenManager", options =>
{
options.Cache(cacheOptions =>
{
cacheOptions.ExpirationOffset = 30; // 15 by default
},
// optional to configure your own IMemoryCache provider for the token management
provider => provider.GetRequiredService<IMemoryCache>());
options.Configuration(overrideConfiguration =>
{
overrideConfiguration.Scopes = ["offline_access"];
});
});
Use the JwtTokenManager
public class MyService(HttpClient httpClient, IJwtTokenManagerService jwtTokenManagerService)
{
public async Task DoActionAsync(CancellationToken cancellationToken) {
var tokenResult = await jwtTokenManagerService.GetTokenAsync(cancellationToken);
httpClient.SetJwtAccessToken(tokenResult);
...
}
}
Description
Releases
12
Languages
C#
100%