【问题标题】:How to get bitbucket's refresh_token?如何获取 bitbucket 的 refresh_token?
【发布时间】:2018-08-16 13:10:43
【问题描述】:

我正在使用以下 API

https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=token

要获取 access_token 但 access_token 在 1 小时内过期,我需要 refresh_token 但我无法在上述 API 的响应中获取 refresh_token。 上述 API 的响应是

https://www.example.com/#access_token={access_token}&scopes={scopes}&expires_in=3600&token_type=bearer

您可以在上面的回复中看到没有 或者有没有其他方法可以获得refresh_token。

我想将上述 API 调用为 GET 方法。

能否请人帮忙。

谢谢!

【问题讨论】:

    标签: bitbucket token access-token bitbucket-api refresh-token


    【解决方案1】:

    编辑:请注意,在重新审视这个问题之后,我不得不说我最初的“解决方案”是不正确的。 Petr's solution above 更合适。如果我造成任何混乱,请道歉。


    我正好面临这个问题,感谢您在 SO 中输入它!

    更好的是,我刚刚找到了解决方案:您需要请求 grant_type=client_credentials:

    curl -X POST -u "your_client_id:your_secret" \ 
         https://bitbucket.org/site/oauth2/access_token \
        -d grant_type=client_credentials
    

    刷新令牌将包含在回复中:

    {
        "access_token": "the_access_token",
        "expires_in": 3600,
        "refresh_token": "the_refresh_token",
        "scopes": "....",
        "token_type": "bearer"
    }
    

    请注意,关于刷新令牌本身,您只需根据此comment from Atlassian team member发出一次此请求:

    ...刷新令牌不会过期。 [...] 访问令牌根据规范过期,刷新令牌不会过期。

    【讨论】:

    • 感谢您的回复。我已经找到了这个解决方案,但问题是我想将它与 REST 客户端而不是 CURL 一起使用。你对此有什么想法吗?
    • 抱歉,您的“如何获取 bitbucket 的 refresh_token?”是指示的解决方案的内容。如果实际问题是如何使用它来检索“刷新的”访问令牌:如developer.atlassian.com/cloud/bitbucket/oauth-2 所述,这需要通过对https://bitbucket.org/site/oauth2/access_token 的POST 请求进行基本身份验证(使用您的client_id和秘密)和表单参数:grant_type=refresh_tokenrefresh_token=<your refresh token>。请查阅您的“REST 客户端”文档以了解如何提出此类请求(或指明您使用的语言/环境)。
    【解决方案2】:

    我得到了一些解决方案。因为我在没有服务器端后端支持的情况下使用基于浏览器的操作。在Atlassian doc 中,他们提到了隐式和 JWT 被排除在 refresh_tokens 之外。如果你也想要 refresh_token ,那么你需要先使用 Authorization Code Grant

    【讨论】:

      【解决方案3】:

      在您的浏览器中转到

      https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code

      使用您的 bitbucket 帐户进行授权。

      之后,您的浏览器将被重定向到

      {your_redirect_link}/?code={code}

      使用代码在终端中发出另一个请求:

      curl -X POST -u "{client_id:secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=authorization_code -d code={code}

      响应将如下所示:

      {
        "access_token": "some_long_string",
        "scopes": "team webhook account issue wiki pipeline pullrequest project snippet",
        "expires_in": 7200,
        "refresh_token": "the_string_you_need",
        "token_type": "bearer"
      }
      

      现在您可以通过请求刷新 access_token

      curl -X POST -u "{client_id}:{secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=refresh_token -d refresh_token={refresh_token}

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-25
        • 1970-01-01
        • 2018-08-01
        相关资源
        最近更新 更多