【问题标题】:Bitbucket API - Unable to Generate Access Token from JWTBitbucket API - 无法从 JWT 生成访问令牌
【发布时间】:2022-01-03 14:52:11
【问题描述】:

我正在使用 Bitbucket Connect 应用程序并从 webhook 事件中获取 JWT 令牌。 当我使用最新的JWT 获取access token 时,访问令牌API 响应返回空白。

API:

curl -X POST -H "Authorization: JWT {jwt_token}" \ https://bitbucket.org/site/oauth2/access_token \ -d grant_type=urn:bitbucket:oauth2:jwt

示例:

curl -X POST -H "Authorization: JWT ey*****XVCJ9.eyJpc3MiOi****asdfQ.**BBD**" \
  https://bitbucket.org/site/oauth2/access_token \
  -d grant_type=urn:bitbucket:oauth2:jwt

回应

{blank}

API 参考

https://developer.atlassian.com/cloud/bitbucket/oauth-2/

谢谢

【问题讨论】:

  • “当我使用最新的 JWT 获取访问令牌时,访问令牌 API 返回空白作为响应”是什么意思?您无法使用访问令牌获取访问令牌?”您需要一个刷新令牌
  • 您要使用哪个流程?如此处所述? developer.atlassian.com/cloud/bitbucket/oauth-2
  • 我正在使用这个:4。 Bitbucket Cloud JWT 授权 (urn:bitbucket:oauth2:jwt) developer.atlassian.com/cloud/bitbucket/oauth-2/…>
  • 抱歉不知道,删除了我的答案以及不正确
  • 这里的示例bitbucket.org/atlassian/bb-cloud-jwt-grant-sample-app/src/…(第 125 行)还添加了内容类型,这有帮助吗?

标签: jwt bitbucket bitbucket-api


【解决方案1】:

在将 sub 键添加到有效负载之前,我遇到了同样的问题。将该值设置为在应用安装生命周期事件期间在clientKey 中收到的值。

【讨论】:

    【解决方案2】:

    我按照此文档生成访问令牌并且它有效。 https://pawelniewiadomski.com/2016/06/06/building-bitbucket-add-on-in-rails-part-7/

    使用Bitbucket Cloud API

    生成访问令牌的大部分部分
    def get_access_token
      unless current_jwt_auth
        raise 'Missing Authentication context'
      end
    
      # Expiry for the JWT token is 3 minutes from now
      issued_at = Time.now.utc.to_i
      expires_at = issued_at + 180
    
      jwt = JWT.encode({
                           iat: issued_at,
                           exp: expires_at,
                           iss: current_jwt_auth.addon_key,
                           sub: current_jwt_auth.client_key
                       }, current_jwt_auth.shared_secret)
    
      response = HTTParty.post("#{current_jwt_auth.base_url}/site/oauth2/access_token", {
          body: {grant_type: 'urn:bitbucket:oauth2:jwt'},
          headers: {
              'Content-Type' => 'application/x-www-form-urlencoded',
              'Authorization' => 'JWT ' + jwt
          }
      })
    
      if response.code == 200
        Response.new(200, response.parsed_response)
      else
        Response.new(response.code)
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2019-11-29
      • 2020-06-12
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      • 2021-02-13
      • 2020-08-11
      • 1970-01-01
      • 2021-07-27
      相关资源
      最近更新 更多