IdentityServer4发现文档返回404

时间:2018-08-11 18:46:15

标签: c# asp.net-core identityserver4

我正在遵循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而不是发现文档。有什么想法吗?

1 个答案:

答案 0 :(得分:7)

步骤列表中缺少的是在UseIdentityServer的{​​{1}}方法中添加Startup。官方docs对此进行了介绍,看起来像这样:

Configure

public void Configure(IApplicationBuilder app, IHostingEnvironment env) { // ... app.UseIdentityServer(); app.UseMvc(...); } 将IdentityServer中间件添加到ASP.NET Core管道中。它的职责之一是为。众所周知的端点服务。