简体   繁体   English

在 WSO2 API-Manager 中创建一个新的访问令牌而不撤销前一个访问令牌

[英]Creating a new access token without revoking the previous one in WSO2 API-Manager

Based on our gateway roles, applications have to authenticate them selves through following Curl基于我们的网关角色,应用程序必须通过以下 Curl 对自己进行身份验证

curl --location --request POST 'https://localhost:9443/oauth2/token' \
--header 'Authorization: Basic BASIC-TOKEN' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cookie: cookiesession1=678B2889RTUVWXYZABCDEFGHIJKLE170' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=USERNAME' \
--data-urlencode 'password=PASSWORD'

The problem is, each time that I call https://localhost:9443/oauth2/token the system provides a new access-token.问题是,每次我调用 https://localhost:9443/oauth2/token 时,系统都会提供一个新的访问令牌。 Also the previous access token would be expired.之前的访问令牌也将过期。

Even if I Call https://localhost:9443/oauth2/token with REFRESH-TOKEN grand-type, the system provides me new access-token again.即使我用 REFRESH-TOKEN grand-type 调用 https://localhost:9443/oauth2/token,系统也会再次为我提供新的访问令牌。

I cannot understand differences between REFRESH-TOKEN and PASSWORD grand-type.我无法理解 REFRESH-TOKEN 和 PASSWORD grand-type 之间的区别。 Why both procedure expired the available access-token and generate a new one?为什么这两个过程都使可用的访问令牌过期并生成一个新的访问令牌?

How can I call https://localhost:9443/oauth2/token and get the available access-token rather than generating a new access-token?我如何调用 https://localhost:9443/oauth2/token 并获取可用的访问令牌而不是生成新的访问令牌?

This is the default behavior of the JWT access tokens.这是 JWT 访问令牌的默认行为。 With JWT token, keymanager does not persist a complete JWT access token in the database but only the JTI value of the JWT token.对于 JWT 令牌,keymanager 不会在数据库中保留完整的 JWT 访问令牌,而只会保留 JWT 令牌的 JTI 值。 Therefore there is no way to get the same access token from the /token call even if the token is not expired.因此,即使令牌未过期,也无法从 /token 调用中获取相同的访问令牌。 That's why every request generates a new token.这就是为什么每个请求都会生成一个新令牌的原因。

In both password and refresh token grant types, you are renewing the previous access token.在密码和刷新令牌授予类型中,您正在更新以前的访问令牌。 With the password grant type, you use the username and password combination while with the refresh grant type, you use the refresh token from a previous token call.对于密码授权类型,您使用用户名和密码组合,而对于刷新授权类型,您使用来自先前令牌调用的刷新令牌。 Both follow the same approach where a new token will be issued with each token call while revoking the previous one[1].两者都遵循相同的方法,即每次令牌调用都会发出一个新令牌,同时撤销前一个令牌 [1]。 This is the default behavior and you can't change it unless you customize the token issuer.这是默认行为,除非您自定义令牌颁发者,否则您无法更改它。 Please find the article [2] which explains how to customize the token generation flow.请找到解释如何自定义令牌生成流程的文章 [2]。

If you use opaque tokens, you can achieve your requirement[3], however, dev portal applications do not support opaque tokens and you have to manually create the Service provider for each application with the token issuer as default instead of JWT.如果您使用不透明令牌,您可以实现您的要求[3],但是,开发门户应用程序不支持不透明令牌,您必须为每个应用程序手动创建服务提供者,默认令牌发行者而不是 JWT。

[1] - https://github.com/arunans23/identity-inbound-auth-oauth-1/blob/master/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/AbstractAuthorizationGrantHandler.java#L337 [1] - https://github.com/arunans23/identity-inbound-auth-oauth-1/blob/master/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/ carbon/identity/oauth2/token/handlers/grant/AbstractAuthorizationGrantHandler.java#L337
[2] - https://wso2.com/blogs/thesource/generate-customized-tokens-in-wso2-api-manager/ [2] - https://wso2.com/blogs/thesource/generate-customized-tokens-in-wso2-api-manager/
[3] - https://apim.docs.wso2.com/en/latest/design/api-security/oauth2/token-persistence/#token-persistence [3] - https://apim.docs.wso2.com/en/latest/design/api-security/oauth2/token-persistence/#token-persistence

Just to add more context from the product architecture/ design perspective this was done to reduce the number of call between key manager and gateway.只是为了从产品架构/设计的角度添加更多上下文,这样做是为了减少密钥管理器和网关之间的调用次数。 This is by design and not a bug.这是设计使然,而不是错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM