IdentityServer4 发现文档返回 404。

21

我正在按照 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. Created a new MVC project dotnet new mvc
  2. Added ID Server dotnet add package IdentityServer4
  3. Modified my service configuration by adding

        services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients());
    
  4. Created Config.cs with:

    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错误而不是发现文档。有什么想法吗?

1个回答

32

你的步骤列表中缺少将UseIdentityServer添加到StartupConfigure方法中。这在官方文档中有介绍,大致如下:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    // ...

    app.UseIdentityServer();
    app.UseMvc(...);
}

UseIdentityServer 将 IdentityServer 中间件添加到 ASP.NET Core 管道中。其中一个职责是提供 .well-known 终结点。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接