Compare commits
No commits in common. "main" and "8.2.0" have entirely different histories.
@ -31,7 +31,7 @@ public class JwtTokenManagerService(JwtTokenManagerOptions options, IHttpClientF
|
|||||||
new ("scopes", string.Join(" ", _scopes))
|
new ("scopes", string.Join(" ", _scopes))
|
||||||
};
|
};
|
||||||
|
|
||||||
if (false == options.IsCredentialsInHeader)
|
if (options.IsCredentialsInHeader)
|
||||||
{
|
{
|
||||||
formContentKeyValues.AddRange([
|
formContentKeyValues.AddRange([
|
||||||
new KeyValuePair<string, string>("client_id", options.ClientId),
|
new KeyValuePair<string, string>("client_id", options.ClientId),
|
||||||
@ -45,9 +45,8 @@ public class JwtTokenManagerService(JwtTokenManagerOptions options, IHttpClientF
|
|||||||
Content = formContent
|
Content = formContent
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.IsCredentialsInHeader)
|
if (false == options.IsCredentialsInHeader)
|
||||||
{
|
{
|
||||||
|
|
||||||
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{options.ClientId}:{options.ClientSecret}"));
|
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{options.ClientId}:{options.ClientSecret}"));
|
||||||
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);
|
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,11 @@ namespace OpenHarbor.JwtTokenManager;
|
|||||||
|
|
||||||
public static class ServiceCollectionExtensions
|
public static class ServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
private static bool _defaultRegistered = false;
|
|
||||||
|
|
||||||
[RequiresDynamicCode("Not AoT safe signature. Will add one in the future.")]
|
[RequiresDynamicCode("Not AoT safe signature. Will add one in the future.")]
|
||||||
public static IServiceCollection AddJwtTokenManager(
|
public static IServiceCollection AddJwtTokenManager(
|
||||||
this IServiceCollection services,
|
this IServiceCollection services,
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
string sectionName,
|
string sectionName,
|
||||||
string? name = null,
|
|
||||||
Action<JwtTokenManagerBuilderOptions>? configureBuilderOptions = null)
|
Action<JwtTokenManagerBuilderOptions>? configureBuilderOptions = null)
|
||||||
{
|
{
|
||||||
if (configuration == null)
|
if (configuration == null)
|
||||||
@ -25,20 +22,22 @@ public static class ServiceCollectionExtensions
|
|||||||
if (string.IsNullOrWhiteSpace(sectionName))
|
if (string.IsNullOrWhiteSpace(sectionName))
|
||||||
throw new ArgumentException("Section name must be provided.", nameof(sectionName));
|
throw new ArgumentException("Section name must be provided.", nameof(sectionName));
|
||||||
|
|
||||||
name ??= sectionName;
|
services.Configure<JwtTokenManagerOptions>(configuration.GetSection(sectionName));
|
||||||
|
|
||||||
services.Configure<JwtTokenManagerOptions>(name, configuration.GetSection(sectionName));
|
|
||||||
|
|
||||||
|
// Apply the builder options
|
||||||
var builderOptions = new JwtTokenManagerBuilderOptions();
|
var builderOptions = new JwtTokenManagerBuilderOptions();
|
||||||
configureBuilderOptions?.Invoke(builderOptions);
|
configureBuilderOptions?.Invoke(builderOptions);
|
||||||
|
|
||||||
services.AddKeyedSingleton<IJwtTokenManagerService>(name, (provider, key) =>
|
// Register the service
|
||||||
|
services.AddSingleton<IJwtTokenManagerService>(provider =>
|
||||||
{
|
{
|
||||||
var optionsMonitor = provider.GetRequiredService<IOptionsMonitor<JwtTokenManagerOptions>>();
|
var optionsMonitor = provider.GetRequiredService<IOptionsMonitor<JwtTokenManagerOptions>>();
|
||||||
var options = optionsMonitor.Get(name);
|
var options = optionsMonitor.Get(Options.DefaultName);
|
||||||
|
|
||||||
|
// Apply additional configuration
|
||||||
builderOptions.AdditionalConfiguration?.Invoke(options);
|
builderOptions.AdditionalConfiguration?.Invoke(options);
|
||||||
|
|
||||||
|
// Configure cache options
|
||||||
var cacheOptions = new JwtTokenManagerCacheOptions();
|
var cacheOptions = new JwtTokenManagerCacheOptions();
|
||||||
builderOptions.CacheOptions?.Invoke(cacheOptions);
|
builderOptions.CacheOptions?.Invoke(cacheOptions);
|
||||||
|
|
||||||
@ -49,24 +48,6 @@ public static class ServiceCollectionExtensions
|
|||||||
return new JwtTokenManagerService(options, httpClientFactory, logger, memoryCache, cacheOptions);
|
return new JwtTokenManagerService(options, httpClientFactory, logger, memoryCache, cacheOptions);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!_defaultRegistered)
|
|
||||||
{
|
|
||||||
services.AddSingleton<IJwtTokenManagerService>(sp =>
|
|
||||||
sp.GetRequiredKeyedService<IJwtTokenManagerService>(name));
|
|
||||||
|
|
||||||
_defaultRegistered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
[RequiresDynamicCode("Not AoT safe signature. Will add one in the future.")]
|
|
||||||
public static IServiceCollection AddJwtTokenManager(
|
|
||||||
this IServiceCollection services,
|
|
||||||
IConfiguration configuration,
|
|
||||||
string sectionName,
|
|
||||||
Action<JwtTokenManagerBuilderOptions>? configureBuilderOptions = null)
|
|
||||||
{
|
|
||||||
return AddJwtTokenManager(services, configuration, sectionName, null, configureBuilderOptions);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user