【问题标题】:IdentityServer4 discovery document returns 404IdentityServer4 发现文档返回 404
【发布时间】:2019-01-19 00:38:20
【问题描述】:

我正在关注 ID Server 4 的快速入门,但有一个例外是我正在使用 .NET Core 2.1.302 的 Mac 上工作。不知何故,当我导航到 http://localhost:5000/.well-known/openid-configuration 时,我得到了 404:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:5000/.well-known/openid-configuration  
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 0.108ms 404 

以下是我采取的步骤:

  1. 创建了一个新的 MVC 项目dotnet new mvc
  2. 添加了 ID 服务器dotnet add package IdentityServer4
  3. 通过添加修改我的服务配置

        services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients());
    
  4. 使用以下内容创建 Config.cs:

    public static IEnumerable<ApiResource> GetApiResources()
    {
        return new List<ApiResource>
        {
            new ApiResource("api1", "My API")
        };
    }
    
    public static IEnumerable<Client> GetClients()
    {
        return new List<Client>
        {
            new Client
            {
                ClientId = "client",
    
                // no interactive user, use the clientid/secret for authentication
                AllowedGrantTypes = GrantTypes.ClientCredentials,
    
                // secret for authentication
                ClientSecrets =
                {
                    new Secret("secret".Sha256())
                },
    
                // scopes that client has access to
                AllowedScopes = { "api1" }
            }
        };
    

当我导航到http://localhost:5000/.well-known/openid-configuration 时,我得到的是 404 而不是发现文档。有什么想法吗?

【问题讨论】:

    标签: c# asp.net-core identityserver4


    【解决方案1】:

    您的步骤列表中缺少的是在您的StartupConfigure 方法中添加UseIdentityServer。它在官方docs 中进行了介绍,看起来像这样:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        // ...
    
        app.UseIdentityServer();
        app.UseMvc(...);
    }
    

    UseIdentityServer 将 IdentityServer 中间件添加到 ASP.NET Core 管道中。它的职责之一是提供 .well-known 端点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 2020-06-12
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 2018-11-09
      • 2023-03-14
      相关资源
      最近更新 更多