c# - 在 Identity Server 4 中为 OpenID Connect 注册 IIdentityServerInteractionService

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

我正尝试在 Adding User Authentication with OpenID Connect 上学习本教程来自 Identity Server 4 文档,但在启动 mvc 客户端时出现以下错误:

InvalidOperationException: Unable to resolve service for type 'IdentityServer4.Services.IIdentityServerInteractionService' while attempting to activate 'IdentityServer4.Quickstart.UI.HomeController'.

如何注册 Identity Server Interaction Service?这听起来像是 DI 的问题。

最佳答案

当依赖项注入(inject)容器中的接口(interface) IIdentityServerInteractionService 没有可用的实现时,您会收到此错误。 快速入门示例的 HomeController 请求在构造函数中实现 IIdentityServerInteractionService:

public HomeController(IIdentityServerInteractionService interaction)
{
    _interaction = interaction;
}

您应该在启动类的ConfigureServices 方法中添加services.AddIdentityServer();。 IdentityServer 将注入(inject) IIdentityServerInteractionService 的实现,命名为 DefaultIdentityServerInteractionService

关于c# - 在 Identity Server 4 中为 OpenID Connect 注册 IIdentityServerInteractionService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41597465/

相关文章:

c# - 为什么 Await 之后的代码不在 UI 线程上运行?

asp.net - Blazor WebAssembly 登录身份验证/从 .well-known/openid-configuration 登录提供本地主机 URL,而不是公共(public) URL

c# - 我如何将计算字段添加到 access_token/id_token

c# - .Net 核心托管服务保证完成

c# - 在控制台应用程序中屏蔽密码参数

c# - 在测试项目中使用 IDataProtectionProvider?

c# - ASP.NET Core - 向用户添加角色声明

asp.net-core - 如何使用 Identity server 4 JWT 身份验证和资源所有者密码授予使 jwt 访问 token 失效或撤销?

c# - StyleCop 4.7 是否与 C# 6.0 代码兼容

c# - 如何区分ASP.NET Core基于属性的路由重载函数