Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IdentityServer4 discovery document returns 404

I am following the quick start for ID Server 4 with one exception that I am working on a Mac with .NET Core 2.1.302. Somehow when I navigate to http://localhost:5000/.well-known/openid-configuration I get a 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 

Here are the steps that I took:

  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" }
            }
        };
    

When I navigate to http://localhost:5000/.well-known/openid-configuration I get a 404 instead of the discovery document. Any ideas?

like image 897
mikebz Avatar asked Aug 11 '18 18:08

mikebz


1 Answers

Missing from your list of of steps is adding UseIdentityServer inside of your Startup's Configure method. It's covered in the official docs and looks something like this:

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

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

UseIdentityServer adds the IdentityServer middleware into the ASP.NET Core pipeline. One of its responsibilities is to serve up the .well-known endpoints.

like image 62
Kirk Larkin Avatar answered Oct 22 '22 13:10

Kirk Larkin