fengling-auth-service/Configuration/OpenIddictSetup.cs
Sam 1a0c18c198 fix: simplify OpenIddict server configuration
- Remove non-existent method calls (AllowAuthorizationCodeFlow, etc)
- Keep only basic configuration: issuer, encryption, scopes
- This should fix 'authorization endpoint must be enabled' error
2026-02-06 21:59:06 +08:00

56 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.DependencyInjection;
namespace Fengling.AuthService.Configuration;
public static class OpenIddictSetup
{
public static IServiceCollection AddOpenIddictConfiguration(
this IServiceCollection services,
IConfiguration configuration
)
{
var isTesting = configuration.GetValue<bool>("Testing", false);
var builder = services.AddOpenIddict();
builder.AddCore(options =>
{
options.UseEntityFrameworkCore().UseDbContext<Data.ApplicationDbContext>();
});
if (!isTesting)
{
builder.AddServer(options =>
{
options.SetIssuer(configuration["OpenIddict:Issuer"] ?? "https://auth.fengling.local");
options.AddDevelopmentEncryptionCertificate()
.AddDevelopmentSigningCertificate();
options.RegisterScopes(
"openid",
"profile",
"email",
"api",
"offline_access"
);
});
}
builder.AddValidation(options =>
{
options.UseLocalServer();
options.UseAspNetCore();
});
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
return services;
}
}