【发布时间】:2018-05-14 11:06:09
【问题描述】:
我正在尝试使用 IdentityServer4 创建身份服务。该服务使用 OWIN (.Net Fx 4.7.x) 自托管。这是我迄今为止尝试过的。
尝试#1:使用documentation 中的示例: 但是,所有示例均基于 .Net 核心。复制 app.UseIdentityServer(); 等代码不起作用,因为在示例中,app 的类型为 IApplicationBuilder,而在 OWIN 自托管应用程序中,我们有 IAppBuilder。
// Startup.cs
public void Configuration(IAppBuilder app)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// Configure Unity IOC
app.UseIdentityServer(); //<--doesn't compile
app.UseWebApi(config);
}
尝试#2:手动注册 IdentityServer 中间件:我尝试通过查看源代码手动注册所需的中间件。如下所示:
//Startup.cs
public void Configuration(IAppBuilder app)
{
...
// Configure Unity IOC
app.Use<IdentityServerMiddleware>(
config.DependencyResolver.GetService(typeof(ILogger<IdentityServerMiddleware>)));
app.UseWebApi(config);
}
这也不起作用,因为Main 方法在使用WebApp.Start<Startup>(baseAddress); 盯着 WebApp 时会引发以下错误
System.Web.Http.Owin.HttpMessageHandlerAdapter 和 Microsoft.AspNetCore.Http.RequestDelegate 之间没有可用的转换。 参数名称:签名
如何正确配置它?我知道在这种情况下我可以使用 IdentityServer3,但我热衷于使用 IdentityServer4,因为不再维护 IdentityServer3。
【问题讨论】:
-
不能,身份服务器 4 仅用于 dotnet 核心。您可以使用 net framework 或不选择创建一个单独的项目作为 dotnet core,然后这将是您所有应用程序进行身份验证的终点。否则你必须使用身份服务器 3。
-
你的问题有点不清楚。您是否尝试使用身份服务器 4 为 .net 4.7 创建身份服务器?或者您是否尝试使用 .net 4.7 连接到身份服务器?
-
@DaImTo 很抱歉造成混乱。更新了问题。我正在尝试创建身份服务。
标签: c# asp.net owin identityserver4 self-host-webapi