【发布时间】:2019-05-21 09:49:26
【问题描述】:
我正在运行一个项目,试图按照this blog 之后的授权代码工作流程获取访问令牌。前往地址
https://localhost:44300/.well-known/openid-configuration
我得到一个列表说
"authorization_endpoint": "https://localhost:44300/connect/authorize", ...
但是,当我尝试 access that endpoint(在 PostMan 和浏览器中获取)时,我得到状态码 404。我选择了
"token_endpoint":"https://localhost:44300/connect/token"
而且效果很好,正如预期的那样。我尝试使用扩展方法CreateAuthorizeUrl(...) 在查询字符串as suggested 中指定参数,没有区别。谷歌搜索 ids4 授权 404 not found 只会命中 borken 路由,在这种情况下,即使是令牌端点也会受到影响。
有人建议实现我们自己的自定义端点,但这违背了 ID Server 的全部目的(而且我相信这些人比我更了解)。
我们确实确保端点是公开的(设置为 false 会将其隐藏在众所周知的范围内)。
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer(opt => opt.Endpoints.EnableAuthorizeEndpoint = true)
.AddInMemoryClients(Clients.Obtain())
.AddInMemoryIdentityResources(IdResources.Obtain())
.AddInMemoryApiResources(ApiResources.Obtain())
.AddInMemoryApiScopes(ApiScopes.Obtain())
.AddTestUsers(TestUsers.Obtain().ToList())
.AddDeveloperSigningCredential();
}
然后就是路由和 IDS(包括添加/移动 AddAuthentication()、AddAutheorization()、.AddDefaultEndpoints() 等的无数种不同组合)。
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
IdentityModelEventSource.ShowPII = true;
app.UseRouting();
app.UseIdentityServer();
}
我们已经为此耗尽了整个团队的智慧。解决问题的明智方法是什么?
【问题讨论】:
-
你有没有可能在 IDS4 之前在管道中注册 MVC?
-
@mackie 是的,我做到了。我去 app.UseIdentityServer() 然后是 app.UseMvc()。我希望在调用被路由到数据源之前 启动安全性。我是否混淆了概念?
-
@mackie 我指的是文档的the last code snippet in Adding UI section。如您所见,他们首先添加 IDS,然后在 MVC 中插入...
标签: c# authorization identityserver4