identityserver4 with redux -oidc client requested access token - but client is not configured to receive access tokens via browser
我的Identityserver4客户端如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | new Client { ClientId ="openIdConnectClient", ClientName ="Example Implicit Client Application", //AllowedGrantTypes = GrantTypes.Implicit, AllowedGrantTypes = GrantTypes.ClientCredentials, ClientSecrets = { new Secret("secret".Sha256()) }, AllowOfflineAccess = true, AllowAccessTokensViaBrowser = true, AccessTokenLifetime = 30, AllowedScopes = new List<string> { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, IdentityServerConstants.StandardScopes.Email, "role", "customAPI.write" }, RedirectUris = new List<string> {"http://localhost:8080/callback"}, PostLogoutRedirectUris = new List<string> {"https://localhost:44330"}, AllowedCorsOrigins = new List<string> { "http://127.0.0.1:8080", "http://localhost:8080", "*" }, } |
在react应用程序中,我的userManager类如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import { createUserManager } from 'redux-oidc'; const userManagerConfig = { client_id: 'openIdConnectClient', redirect_uri: `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}/callback`, //response_type: 'code id_token token', response_type: 'token id_token', scope: 'openid profile email role', authority: 'http://localhost:50604', silent_redirect_uri: `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}/silent_renew.html`, automaticSilentRenew: true, filterProtocolClaims: true, loadUserInfo: true, }; const userManager = createUserManager(userManagerConfig); export default userManager; |
问题是:当我尝试从redux-oidc示例应用程序调用我的identityserver4时。我收到以下错误:
Client requested access token - but client is not configured to receive access tokens via browser
希望您能理解这个问题。请有人帮助我。我已经为以下示例应用程序提供了链接。
Redux-oidc示例应用程序链接
您的代码包含两种不同的赠款类型。身份服务器4中的不同授予类型具有不同的要求。这里有一些信息可以帮助您了解所使用的不同类型。它还可以帮助您了解为什么会遇到此问题。
GrantTypes.ClientCredentials
客户端凭据是最简单的授予类型,用于服务器到服务器的通信-令牌始终代表客户端而不是用户请求。
使用此授予类型,您可以向令牌端点发送令牌请求,并获得代表客户端的访问令牌。客户端通常必须使用其客户端ID和密码与令牌端点进行身份验证。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | new Client { ClientId ="client", // no interactive user, use the clientid/secret for authentication AllowedGrantTypes = GrantTypes.ClientCredentials, // secret for authentication ClientSecrets = { new Secret("secret".Sha256()) }, // scopes that client has access to AllowedScopes = {"api1" } } |
GrantTypes.Implicit
隐式授予类型针对基于浏览器的应用程序进行了优化。仅用于用户身份验证(服务器端和JavaScript应用程序),或者用于身份验证和访问令牌请求(JavaScript应用程序)。
在隐式流中,所有令牌都是通过浏览器传输的,因此不允许使用高级功能(如刷新令牌)。如果要通过浏览器通道传输访问令牌,则还需要在客户端配置上明确允许该令牌:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | Client.AllowAccessTokensViaBrowser = true; new Client { ClientId ="mvc", ClientName ="MVC Client", AllowedGrantTypes = GrantTypes.Implicit, // where to redirect to after login RedirectUris = {"http://localhost:5002/signin-oidc" }, // where to redirect to after logout PostLogoutRedirectUris = {"http://localhost:5002/signout-callback-oidc" }, AllowedScopes = new List<string> { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile }, AllowAccessTokensViaBrowser = true } |