Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
20518b8f6a | |||
8249714c6b | |||
7e1e5c76b7 | |||
6fee2c5c9a | |||
0f1f900055 | |||
892101a84d | |||
3478750bc9 | |||
e7ebf0cf19 | |||
4c5b5aec66 | |||
6bebdf916c | |||
2e4a8b6d98 | |||
602076b669 |
@ -35,4 +35,4 @@ jobs:
|
|||||||
|
|
||||||
- name: Publish to NuGet.org
|
- name: Publish to NuGet.org
|
||||||
run: |
|
run: |
|
||||||
dotnet nuget push ./artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
|
dotnet nuget push ./artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
|
@ -2,14 +2,28 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<IsAotCompatible>true</IsAotCompatible>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Authors>Mathias Beaulieu-Duncan</Authors>
|
<Authors>Mathias Beaulieu-Duncan</Authors>
|
||||||
<PackageIconUrl>https://gravatar.com/avatar/9cecda5822fc5d4d2e61ec03da571b3d?size=256</PackageIconUrl>
|
<Company>Open Harbor</Company>
|
||||||
|
<PackageIcon>icon.png</PackageIcon>
|
||||||
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<RepositoryUrl>https://git.openharbor.io/Open-Harbor/dotnet-jwt-token-manager</RepositoryUrl>
|
<RepositoryUrl>https://git.openharbor.io/Open-Harbor/dotnet-jwt-token-manager</RepositoryUrl>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
|
||||||
|
<DebugType>portable</DebugType>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
|
<IncludeSource>true</IncludeSource>
|
||||||
|
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\icon.png" Pack="true" PackagePath="" CopyToOutputDirectory="Always" />
|
||||||
|
<None Include="..\README.md" Pack="true" PackagePath="" CopyToOutputDirectory="Always" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
12
OpenHarbor.JwtTokenManager/JwtTokenManagerJsonContext.cs
Normal file
12
OpenHarbor.JwtTokenManager/JwtTokenManagerJsonContext.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace OpenHarbor.JwtTokenManager;
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(
|
||||||
|
PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower,
|
||||||
|
PropertyNameCaseInsensitive = true
|
||||||
|
)]
|
||||||
|
[JsonSerializable(typeof(JwtTokenResponse))]
|
||||||
|
public partial class JwtTokenManagerJsonContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Text.Json;
|
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using OpenHarbor.JwtTokenManager.Abstractions;
|
using OpenHarbor.JwtTokenManager.Abstractions;
|
||||||
@ -14,12 +13,6 @@ public class JwtTokenManagerService(JwtTokenManagerOptions options, IHttpClientF
|
|||||||
private readonly TimeSpan _cacheExpirationOffset = TimeSpan.FromSeconds(cacheOptions.ExpirationOffset);
|
private readonly TimeSpan _cacheExpirationOffset = TimeSpan.FromSeconds(cacheOptions.ExpirationOffset);
|
||||||
private readonly string _scopes = string.Join(" ", options.Scopes);
|
private readonly string _scopes = string.Join(" ", options.Scopes);
|
||||||
|
|
||||||
private static readonly JsonSerializerOptions SnakeCaseOptions = new()
|
|
||||||
{
|
|
||||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
|
||||||
PropertyNameCaseInsensitive = true
|
|
||||||
};
|
|
||||||
|
|
||||||
public async Task<JwtTokenManagerResult> GetTokenAsync(CancellationToken cancellationToken = default)
|
public async Task<JwtTokenManagerResult> GetTokenAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (memoryCache != null)
|
if (memoryCache != null)
|
||||||
@ -49,7 +42,7 @@ public class JwtTokenManagerService(JwtTokenManagerOptions options, IHttpClientF
|
|||||||
|
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var tokenResponse = await response.Content.ReadFromJsonAsync<JwtTokenResponse>(SnakeCaseOptions, cancellationToken);
|
var tokenResponse = await response.Content.ReadFromJsonAsync(JwtTokenManagerJsonContext.Default.JwtTokenResponse, cancellationToken);
|
||||||
|
|
||||||
if (tokenResponse == null)
|
if (tokenResponse == null)
|
||||||
{
|
{
|
||||||
|
@ -2,16 +2,32 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<IsAotCompatible>true</IsAotCompatible>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Authors>Mathias Beaulieu-Duncan</Authors>
|
<Authors>Mathias Beaulieu-Duncan</Authors>
|
||||||
<PackageIconUrl>https://gravatar.com/avatar/9cecda5822fc5d4d2e61ec03da571b3d?size=256</PackageIconUrl>
|
<Company>Open Harbor</Company>
|
||||||
|
<PackageIcon>icon.png</PackageIcon>
|
||||||
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<RepositoryUrl>https://git.openharbor.io/Open-Harbor/dotnet-jwt-token-manager</RepositoryUrl>
|
<RepositoryUrl>https://git.openharbor.io/Open-Harbor/dotnet-jwt-token-manager</RepositoryUrl>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
|
||||||
|
<DebugType>portable</DebugType>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
|
<IncludeSource>true</IncludeSource>
|
||||||
|
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||||
|
|
||||||
|
<EnableJsonSourceGeneration>true</EnableJsonSourceGeneration>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\icon.png" Pack="true" PackagePath="" CopyToOutputDirectory="Always" />
|
||||||
|
<None Include="..\README.md" Pack="true" PackagePath="" CopyToOutputDirectory="Always" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@ -9,6 +10,7 @@ namespace OpenHarbor.JwtTokenManager;
|
|||||||
|
|
||||||
public static class ServiceCollectionExtensions
|
public static class ServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
|
[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,
|
||||||
@ -19,8 +21,7 @@ public static class ServiceCollectionExtensions
|
|||||||
throw new ArgumentNullException(nameof(configuration));
|
throw new ArgumentNullException(nameof(configuration));
|
||||||
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));
|
||||||
|
|
||||||
// Configure JwtTokenManagerOptions from the section
|
|
||||||
services.Configure<JwtTokenManagerOptions>(configuration.GetSection(sectionName));
|
services.Configure<JwtTokenManagerOptions>(configuration.GetSection(sectionName));
|
||||||
|
|
||||||
// Apply the builder options
|
// Apply the builder options
|
||||||
@ -30,7 +31,7 @@ public static class ServiceCollectionExtensions
|
|||||||
// Register the service
|
// Register the service
|
||||||
services.AddSingleton<IJwtTokenManagerService>(provider =>
|
services.AddSingleton<IJwtTokenManagerService>(provider =>
|
||||||
{
|
{
|
||||||
var optionsMonitor = provider.GetRequiredService<Microsoft.Extensions.Options.IOptionsMonitor<JwtTokenManagerOptions>>();
|
var optionsMonitor = provider.GetRequiredService<IOptionsMonitor<JwtTokenManagerOptions>>();
|
||||||
var options = optionsMonitor.Get(Options.DefaultName);
|
var options = optionsMonitor.Get(Options.DefaultName);
|
||||||
|
|
||||||
// Apply additional configuration
|
// Apply additional configuration
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
|
|
||||||
> Install nuget package to your awesome project.
|
> Install nuget package to your awesome project.
|
||||||
|
|
||||||
| Full Version | NuGet | NuGet Install |
|
| Package Name | NuGet | NuGet Install |
|
||||||
|-----------------------------------------| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |----------------------------------------------------------------------------:|
|
|-----------------------------------------| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |----------------------------------------------------------------------------:|
|
||||||
| OpenHarbor.JwtTokenManager | <a href="https://www.nuget.org/packages/OpenHarbor.JwtTokenManager" target="_blank">[![NuGet](https://img.shields.io/nuget/v/OpenHarbor.JwtTokenManager.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/OpenHarbor.JwtTokenManager/)</a> | ```PM> Install-Package OpenHarbor.JwtTokenManager``` |
|
| OpenHarbor.JwtTokenManager | [![NuGet](https://img.shields.io/nuget/v/OpenHarbor.JwtTokenManager.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/OpenHarbor.JwtTokenManager/) | ```PM> Install-Package OpenHarbor.JwtTokenManager``` |
|
||||||
| OpenHarbor.JwtTokenManager.Abstractions | <a href="https://www.nuget.org/packages/OpenHarbor.JwtTokenManager.Abstractions" target="_blank">[![NuGet](https://img.shields.io/nuget/v/OpenHarbor.JwtTokenManager.Abstractions.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/OpenHarbor.JwtTokenManager.Abstractions/)</a> | ```PM> Install-Package OpenHarbor.JwtTokenManager.Abstractions``` |
|
| OpenHarbor.JwtTokenManager.Abstractions | [![NuGet](https://img.shields.io/nuget/v/OpenHarbor.JwtTokenManager.Abstractions.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/OpenHarbor.JwtTokenManager.Abstractions/) | ```PM> Install-Package OpenHarbor.JwtTokenManager.Abstractions``` |
|
||||||
|
|
||||||
# How to use
|
# How to use
|
||||||
|
|
Loading…
Reference in New Issue
Block a user