我是 Identity Server 4 的新手,我正在关注官方 QuickStarts .
文档建议尝试一下选项,这样人们就可以了解这一切是如何工作的。但在我尝试了最后一个“进一步实验”点后,我遇到了麻烦。
当我更改 API Startup.cs 文件上的 ApiName 时,如下所示:
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:5000",
RequireHttpsMetadata = false,
ApiName = "api2" //<-- this was api1
});
我仍在从客户端应用程序获取结果(执行 API 的 IdentityController 并返回用户声明的 json 数据)。
阅读文档(也可能根据常见逻辑)我相信,如果客户端应用程序获得与 API 所需的范围不同的范围(又名 ApiName),则它不应该能够访问 Controller 。
我对流程的理解错了还是什么?
最佳答案
我也不确定这一点,但我认为 ApiName 不是范围。如果添加
AllowedScopes = {"api2"} 添加到选项中,那么您将得到“Forbidden”结果。
关于asp.net-identity - 更改 IdentityServerAuthenticationOptions 客户端上的 ApiName 后仍然可以使用 Identity Server 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41768949/