【问题标题】:WSO2 API Manager Client Credentials renew tokenWSO2 API Manager 客户端凭据更新令牌
【发布时间】:2015-10-28 19:42:00
【问题描述】:

我正在尝试更新通过 API Manager 生成的令牌。

生成令牌的curl语句为:

curl -k -d "grant_type=client_credentials" -H "Authorization: Basic TDQ0SktDZm5DcVVDSVBjdGYwVDIyRWwwUGY4YT
o2d19NQm9xYnBFXzRLNHR0Wkc0NXhxd0NMTDRh , Content-Type: application/x-www-form-urlencoded" https://10.108.106.214:8250/token

回复是

"scope":"am_application_scope default","token_type":"bearer","expires_in":1094,"access_token":"6d1d0f8afbd147d24bcd42bbc5361a1"

根据文档,它应该生成一个未生成的重新令牌。我错过了什么?

当我将grant_type 作为refresh_token 传递时。我收到一个无效的授权错误。

curl -X POST -H "Authorization: Basic TDQ0SktDZm5DcVVDSVBjdGYwVDIyRWwwUGY4YTo2d19NQm9xYnBFXzRLNHR0Wkc0NXhxd0NMTDRh"  -H "Content-Type: application/x-www-form-urlencoded" -d 'grant_type=refresh_token&refresh_token=6d1d0f8afbd147d24bcd42bbc5361a1' 'https://10.108.106.214:8250/token'

我指的是 URL 中的文档 https://docs.wso2.com/display/AM191/Token+API#TokenAPI-RenewingaccesstokensRenewing

那么我错过了什么?

【问题讨论】:

    标签: oauth-2.0 wso2 wso2-am


    【解决方案1】:

    根据OAuth 2.0 Authorization Protocol 规范,grant_type client_credentials 不应发出刷新令牌。

    4.4.3. Access Token Response

    如果访问令牌请求有效且授权,则授权 服务器如第 5.1 节所述发出访问令牌。 刷新 不应包含令牌。

    你必须使用Password Grant Type

    请求:

    curl -k -d "grant_type=password&username=admin&password=admin" -H "Authorization: Basic bkxidjNPTnYxQ25iTXBRY2E3V3hPajdaMUVZYTpuTUQzX0tKQkhGRmxFUUlXdllmSjdTUFlleThh, Content-Type: application/x-www-form-urlencoded" https://localhost:8243/token
    

    回应:

    {"scope":"default","token_type":"bearer","expires_in":3247,"refresh_token":"91729a78a96b58d80d869f3ec2ce8b8","access_token":"ec54b39dd9503c9f65df84b67ea586"}
    

    使用refresh_tokenRenewing access tokens

    【讨论】:

    • 谢谢,这就解释了。
    • 我们如何通过 HttpClient 或 Resttemplates 创建 Java 代码?能否请你帮忙?或者如何使用 POstman 或 RestTemplates 谢谢,Neha
    • java客户端有什么用途?
    【解决方案2】:

    如果我没记错的话,在您收到的回复中。

    "scope":"am_application_scope default","token_type":"bearer","expires_in":1094,"access_token":"6d1d0f8afbd147d24bcd42bbc5361a1"
    

    这是新的访问令牌。

    access_token":"6d1d0f8afbd147d24bcd42bbc5361a1"
    

    记下当前令牌,然后再次运行 curl 命令。响应应该是不同的令牌。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-06
      • 2020-12-26
      • 2018-12-14
      • 1970-01-01
      • 2019-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多