【问题标题】:Creating a new access token without revoking the previous one in WSO2 API-Manager创建一个新的访问令牌而不撤销 WSO2 API-Manager 中的前一个访问令牌
【发布时间】:2023-02-12 01:27:11
【问题描述】:

基于我们的网关角色,应用程序必须通过以下 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'

问题是,每次我调用 https://localhost:9443/oauth2/token 时,系统都会提供一个新的访问令牌。之前的访问令牌也将过期。

即使我使用 REFRESH-TOKEN grand-type 调用 https://localhost:9443/oauth2/token,系统也会再次为我提供新的访问令牌。

我无法理解 REFRESH-TOKEN 和 PASSWORD grand-type 之间的区别。为什么这两个过程都使可用的访问令牌过期并生成一个新的访问令牌?

我如何调用 https://localhost:9443/oauth2/token 并获取可用的访问令牌而不是生成新的访问令牌?

【问题讨论】:

    标签: wso2 wso2-api-manager wso2-identity-server


    【解决方案1】:

    只是为了从产品架构/设计的角度添加更多上下文,这样做是为了减少密钥管理器和网关之间的调用次数。这是设计使然,而不是错误。

    【讨论】:

      【解决方案2】:

      这是 JWT 访问令牌的默认行为。使用 JWT 令牌,keymanager 不会在数据库中保留完整的 JWT 访问令牌,而只会保留 JWT 令牌的 JTI 值。因此,即使令牌未过期,也无法从 /token 调用中获取相同的访问令牌。这就是为什么每个请求都会生成一个新令牌的原因。

      在密码和刷新令牌授予类型中,您正在更新以前的访问令牌。对于密码授权类型,您使用用户名和密码组合,而对于刷新授权类型,您使用来自先前令牌调用的刷新令牌。两者都遵循相同的方法,即每次令牌调用都会发出一个新令牌,同时撤销前一个令牌 [1]。这是默认行为,除非您自定义令牌颁发者,否则您无法更改它。请找到解释如何自定义令牌生成流程的文章 [2]。

      如果您使用不透明令牌,您可以实现您的要求[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
      [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

      【讨论】:

        猜你喜欢
        • 2019-04-12
        • 1970-01-01
        • 2018-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-29
        • 2015-03-06
        相关资源
        最近更新 更多