c# - Identity Server 4 隐式流 - 未知错误
问题描述
我有一个在 .NET 5 上运行的 Identity Server 4 以及一个使用 oidc-client.js 库的简单 JS SPA 客户端
问题是我无法让我的身份服务器使用隐式身份验证。我的 SPA 客户端在 https://localhost:44334 上运行,Identity Server 在 https://localhost:5005 上运行
当我单击登录时,我正在尝试使用 oidc-client.js 从 IdentityServer 获取令牌
var config = {
authority: "https://localhost:5005",
client_id: "react-client",
redirect_uri: "https://localhost:44334/callback.html",
response_type: "id_token token",
scope: "openid profile Api1",
post_logout_redirect_uri: "https://localhost:44334/index.html",
};
var mgr = new Oidc.UserManager(config);
mgr.getUser().then(function (user) {
if (user) {
log("User logged in", user.profile);
}
else {
log("User not logged in");
}
});
function login() {
mgr.signinRedirect();
}
这是我在身份服务器上的客户端配置
return new IdentityServer4.Models.Client
{
ClientId = "react-client",
ClientName = "React Client",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RedirectUris = { "https://localhost:44334/callback.html" },
PostLogoutRedirectUris = { "https://localhost:44334/index.html" },
AllowedCorsOrigins = { "https://localhost:44334" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"Api1"
}
};
现在的问题是,当我单击登录按钮时,浏览器正在重定向到 IdentityServer,但随后显示此错误。
我做错了什么?
解决方案
我发现了问题并解决了。问题是 Api1 未在 Identity Server 的 ApiScopes 配置中列出。IdentityServer 显示的错误非常笼统,无法解决问题。
推荐阅读
- vb.net - 同时更新绑定到相同绑定源VB.Net的两个控件
- containers - 以非 root 身份构建/安装 podman
- sql-server - 授予对数据库 RDS SQL Server 的访问权限
- android - 安卓遥控锁
- javascript - 如何取消绑定按钮上的现有点击事件并将其替换为 Javascript 中的新事件
- groovy - 如何获取 testRunner 属性或方法的列表,在 testRunner 等实例之后输入 .(dot)
- android - Kotlin 编译器错误:无法访问 OkHttpClient
- c - Makefile 中的自动变量未正确扩展
- nativescript - 有没有办法获得 ActionBar 的高度?
- swift - 位置管理器仅在首次启动时展开错误