未处理 OpenIddict 授权请求

OpenIddict authorization request not handled

我正在尝试 OpenIddict 3.0 在 SSO 应用程序中使用。我按照文档中的步骤创建了一个授权控制器,并添加了一个测试应用程序。当我尝试连接以授权时,出现此异常:

System.InvalidOperationException: The authorization request was not handled. To handle authorization requests, create a class implementing 'IOpenIddictServerHandler' and register it using 'services.AddOpenIddict().AddServer().AddEventHandler()'.
Alternatively, enable the pass-through mode to handle them at a later stage.

我在文档或示例应用程序中找不到任何解释这意味着什么的内容。我错过了什么?


到目前为止,这是我的代码。在 Startup.cs:

services.AddOpenIddict()
    .AddCore(o =>
    {
        o.UseEntityFrameworkCore().UseDbContext<ApplicationDbContext>();
    })
    .AddServer(o =>
    {
        o.SetTokenEndpointUris("/connect/token");
        o.SetAuthorizationEndpointUris("/connect/authorize");

        o.AllowAuthorizationCodeFlow();

        o.RegisterScopes(OpenIddictConstants.Scopes.Email);

        o.AcceptAnonymousClients();
        o.AddDevelopmentEncryptionCertificate()
            .AddDevelopmentSigningCertificate();
        o.UseAspNetCore()
            .EnableTokenEndpointPassthrough()
            .DisableTransportSecurityRequirement();
    })
    .AddValidation(o =>
    {
        o.UseLocalServer();
        o.UseAspNetCore();
    });

测试应用说明:

var descriptor = new OpenIddictApplicationDescriptor
{
    ClientId = "test-app",
    DisplayName = "Test Application",
    PostLogoutRedirectUris = { new Uri("https://oidcdebugger.com/debug") },
    RedirectUris = { new Uri("https://oidcdebugger.com/debug") }
};

我正在使用 OpenID Connect debugger 进行测试。

要在 MVC 控制器中处理授权请求,您必须告诉 OpenIddict 的 ASP.NET 核心主机使用直通模式,就像您对令牌端点所做的一样:

services.AddOpenIddict()
    .AddServer(options =>
    {
        options.UseAspNetCore()
               .EnableAuthorizationEndpointPassthrough() // Add this line.
               .EnableTokenEndpointPassthrough()
               .DisableTransportSecurityRequirement();
    });