Browse Source

fix: copy jwks.json to client output and use ILogger in ServerDataSeedContributor

pull/25068/head
maliming 5 months ago
parent
commit
3786ddf3d5
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 9
      modules/openiddict/app/OpenIddict.Demo.Client.Console/OpenIddict.Demo.Client.Console.csproj
  2. 12
      modules/openiddict/app/OpenIddict.Demo.Server/EntityFrameworkCore/ServerDataSeedContributor.cs

9
modules/openiddict/app/OpenIddict.Demo.Client.Console/OpenIddict.Demo.Client.Console.csproj

@ -14,12 +14,15 @@
</ItemGroup>
<ItemGroup>
<!-- jwks-private.pem is the private key for the AbpConsoleAppWithJwks client, used to sign JWT client assertions.
The corresponding public key (jwks.json) is registered on the server side (OpenIddict.Demo.Server).
Both files originate from the parent app/ directory. -->
<!-- jwks-private.pem and jwks.json are generated by 'abp generate-jwks' in the parent app/ directory.
jwks-private.pem: private key used to sign client assertion JWTs.
jwks.json: public JWKS used to read the kid claim and stay in sync with the server-registered key. -->
<None Include="..\jwks-private.pem" Condition="Exists('..\jwks-private.pem')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\jwks.json" Condition="Exists('..\jwks.json')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

12
modules/openiddict/app/OpenIddict.Demo.Server/EntityFrameworkCore/ServerDataSeedContributor.cs

@ -1,4 +1,6 @@
using System.Globalization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.IdentityModel.Tokens;
using OpenIddict.Abstractions;
using OpenIddict.Demo.Server.ExtensionGrants;
@ -14,6 +16,8 @@ public class ServerDataSeedContributor : IDataSeedContributor, ITransientDepende
private readonly IOpenIddictApplicationManager _applicationManager;
private readonly IOpenIddictScopeManager _scopeManager;
public ILogger<ServerDataSeedContributor> Logger { get; set; }
public ServerDataSeedContributor(
ICurrentTenant currentTenant,
IOpenIddictApplicationManager applicationManager,
@ -22,6 +26,7 @@ public class ServerDataSeedContributor : IDataSeedContributor, ITransientDepende
_currentTenant = currentTenant;
_applicationManager = applicationManager;
_scopeManager = scopeManager;
Logger = NullLogger<ServerDataSeedContributor>.Instance;
}
public async Task SeedAsync(DataSeedContext context)
@ -169,10 +174,11 @@ public class ServerDataSeedContributor : IDataSeedContributor, ITransientDepende
var jwksPath = Path.Combine(AppContext.BaseDirectory, "jwks.json");
if (!File.Exists(jwksPath))
{
Console.WriteLine(
$"[OpenIddict] WARNING: JWKS file not found at '{jwksPath}'. " +
Logger.LogWarning(
"JWKS file not found at '{JwksPath}'. " +
"Skipping creation of the 'AbpConsoleAppWithJwks' client. " +
"Run 'abp generate-jwks' in the app/ directory to generate the key pair.");
"Run 'abp generate-jwks' in the app/ directory to generate the key pair.",
jwksPath);
}
else
{

Loading…
Cancel
Save