You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在现有应用中部署Duende Identity Framework并配置指定路径?

在现有ASP.NET应用中嵌入Duende IdentityServer的配置步骤

1. 安装必要的NuGet包

  • 安装核心包:Duende.IdentityServer
  • 若依赖ASP.NET Identity,额外安装:Duende.IdentityServer.AspNetIdentity

2. 配置IdentityServer服务与Issuer URI

在项目的Program.cs(.NET 6+)或Startup.cs(.NET 5及更早)中,配置IdentityServer服务时指定Issuer和基础路径:

builder.Services.AddIdentityServer(options =>
{
    // 设置目标Issuer地址
    options.IssuerUri = "https://localhost:5001/idp";
    // 指定公共源与基础路径,确保所有端点挂载在/idp下
    options.PublicOrigin = "https://localhost:5001";
    options.BasePath = "/idp";
})
// 替换为你的实际配置(客户端、身份资源、API范围)
.AddInMemoryClients(Config.Clients)
.AddInMemoryIdentityResources(Config.IdentityResources)
.AddInMemoryApiScopes(Config.ApiScopes)
// 若使用ASP.NET Identity,添加此配置
.AddAspNetIdentity<ApplicationUser>();

3. 挂载IdentityServer中间件到/idp路径

在中间件管道中,将IdentityServer相关中间件映射到/idp路径下:

app.Map("/idp", idpApp =>
{
    idpApp.UseIdentityServer();
    idpApp.UseAuthorization();
});

4. 调整UI页面到Pages/idp目录

  1. 若使用Duende官方快速启动UI,将所有UI页面复制到项目的Pages/idp目录下
  2. 修改每个UI页面的路由前缀,确保路径以/idp开头:
    比如登录页Login.cshtml的路由声明:
    @page "/idp/account/login"
    
    注册、授权确认等页面同理,统一调整路由为/idp/account/[页面名称]
  3. 检查并更新UI内的所有链接(导航、表单提交地址等),确保指向/idp开头的路径

5. 验证配置有效性

  • 启动应用后,访问https://localhost:5001/idp/.well-known/openid-configuration,确认返回的issuer字段为https://localhost:5001/idp
  • 测试登录、授权等核心流程,验证UI页面与端点均正常工作

内容的提问来源于stack exchange,提问作者acmoune

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 14:30:08