c# - OpenIddict 授权请求未处理

标签 c# asp.net-core openid-connect openiddict

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

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 Controller 中处理授权请求,您必须告诉 OpenIddict 的 ASP.NET Core 主机使用传递模式,就像您对 token 端点所做的那样:

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

关于c# - OpenIddict 授权请求未处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59673567/

相关文章:

c# - 如何通过串口发送一个缓冲区中的所有数据?

c# - 通过串行端口通过诺基亚手机发送短信

c# - 从基类的构造函数访问子类的属性

具有 ASP.NET Web API 验证的 Angular 2

asp.net - 找不到类型或命名空间名称 'ApiVersionDescription'(是否缺少 using 指令或程序集引用?)

c# - 如何在 C# 的下拉列表中获取当前星期几

c# - 点网核心 3.x PublishSingleFile : Temp files get deleted

android - Android 中的 Oauth2 刷新 token 更新

asp.net-web-api - 与多个 B2C 租户共享单个 WebApp 和 API 部署

identityserver4 - 为什么混合流是 IdentityServer 中 Web 应用程序的默认推荐选项?