Identity Server 4 隐式流程 - 未知错误
Identity Server 4 Implicit Flow - Unknown Error
我在 .NET 5 上有一个 Identity Server 4 运行 以及一个使用 oidc-client.js 库
的简单 JS SPA 客户端
问题是我无法让我的身份服务器使用隐式身份验证。
我的 SPA 客户端是 https://localhost:44334 上的 运行 和 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();
}
这是我在 Identity Server 上的客户端配置
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 显示的错误非常普遍,无法解决问题。
我在 .NET 5 上有一个 Identity Server 4 运行 以及一个使用 oidc-client.js 库
的简单 JS SPA 客户端问题是我无法让我的身份服务器使用隐式身份验证。 我的 SPA 客户端是 https://localhost:44334 上的 运行 和 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();
}
这是我在 Identity Server 上的客户端配置
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 显示的错误非常普遍,无法解决问题。