IdentityServer4发现文档返回404 [英] IdentityServer4 discovery document returns 404
问题描述
我正在遵循ID Server 4的快速入门,但有一个例外,我在使用.NET Core 2.1.302的Mac上工作.当我导航到http://localhost:5000/.well-known/openid-configuration
时,我会得到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
这是我采取的步骤:
- 创建了一个新的MVC项目
dotnet new mvc
- 添加了ID服务器
dotnet add package IdentityServer4
-
通过添加修改了我的服务配置
- Created a new MVC project
dotnet new mvc
- Added ID Server
dotnet add package IdentityServer4
Modified my service configuration by adding
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients());
使用以下命令创建的Config.cs:
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-配置,我得到的是404而不是发现文档.有什么想法吗?
When I navigate to http://localhost:5000/.well-known/openid-configuration I get a 404 instead of the discovery document. Any ideas?
推荐答案
步骤列表中遗漏的是在Startup
的Configure
方法内添加了UseIdentityServer
.官方文档看起来像这样:
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
将IdentityServer中间件添加到ASP.NET Core管道中.它的职责之一就是为.众所周知的端点服务.
UseIdentityServer
adds the IdentityServer middleware into the ASP.NET Core pipeline. One of its responsibilities is to serve up the .well-known endpoints.
这篇关于IdentityServer4发现文档返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!