javascript - 客户端未配置为通过浏览器 IdentityServer4 接收访问令牌
问题描述
let usrMgr = new UserManager({
authority: "https://localhost:5001/",
client_id: "clientname",
redirect_uri: "https://localhost:3000/login/callback.html",
response_type: "id_token token",
scope: "openid"
});
usrMgr.signinRedirect();
我正在使用oidc-client-js 向我们的身份服务器进行身份验证,如上所示。
尝试进行身份验证时,我从身份服务器收到以下错误
我在身份服务器上的客户端看起来像这样
{
"Enabled": true,
"ClientId": "clientname",
"ClientName": "Some Client Name",
"AllowedGrantTypes": "implicit",
"AllowedScopes": [ "openid", "profile", "email", "id:custom" ],
"AllowOfflineAccess": true,
"PostLogoutRedirectUris": [ "https://localhost:3000/signout-callback-oidc" ],
"RedirectUris": [ "https://localhost:3000/login/callback.html" ],
"FrontChannelLogoutUri": "https://localhost:3000/signout-oidc",
"AllowAccessTokensViaBrowser": true
}
我将 AllowAccessTokensViaBrowser 设置为 true,并将 AllowedGrantTypes 设置为隐式。
任何想法为什么我会收到“客户端未配置为通过浏览器错误接收访问令牌?
解决方案
如果您查看 IdentityServer 源代码,您会看到
//////////////////////////////////////////////////////////
// check if response type contains an access token,
// and if client is allowed to request access token via browser
//////////////////////////////////////////////////////////
var responseTypes = responseType.FromSpaceSeparatedString();
if (responseTypes.Contains(OidcConstants.ResponseTypes.Token))
{
if (!request.Client.AllowAccessTokensViaBrowser)
{
LogError("Client requested access token - but client is not configured to receive access tokens via browser", request);
return Invalid(request, description: "Client not configured to receive access tokens via browser");
}
}
所以,我认为唯一的原因是如果您的配置文件中有一些拼写错误,或者有其他原因,AllowAccessTokensViaBrowser 未设置为 true。源代码可以在这里找到。也许是一些大写/小写问题?