代码之家  ›  专栏  ›  技术社区  ›  u123

使用curl/REST和token将SSH公钥上传到bitbucket云

  •  5
  • u123  · 技术社区  · 7 年前

    https://id.atlassian.com/manage/api-tokens 我已经生成了一个API令牌,我正试图在REST调用中使用它来上传

    https://docs.atlassian.com/bitbucket-server/rest/5.6.2/bitbucket-ssh-rest.html?utm_source=%2Fstatic%2Frest%2Fbitbucket-server%2F5.6.2%2Fbitbucket-ssh-rest.html&utm_medium=301#idm45427244388592

    https://community.atlassian.com/t5/Answers-Developer-Questions/Bitbucket-REST-API-POST-using-token-instead-of-basic-auth/qaq-p/474823

    我试过:

    curl -X POST -d '{"text":"ssh-rsa AAAAB3... me@127.0.0.1"}' -H "Authorization: Bearer ADasdaEeasAsd..." https://bitbucket.org/[my-account]]/rest/ssh/latest/keys
    

    但当我跑的时候我得到:

    {"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}
    

    有什么建议吗?

    curl -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer wxdrtblabla..." \
    -d '{"key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqP3Cr632C2dNhhgKVcon4ldUSAeKiku2yP9O9/bDtY myuser@bitbucket.org/myuser"}' \
    https://api.bitbucket.org/2.0/users/myuser/ssh-keys
    

    但我得到了完全相同的错误:

    {“type”:“error”,“error”:{“message”:“访问令牌已过期。使用刷新令牌获取新的访问令牌。“}}
    

    https://api.bitbucket.org/2.0/users/[myuser]/ssh-keys

    type    "error"
    error   
    message "This API is only accessible with the following authentication types: session, password, apppassword"
    

    编辑/回答: 根据下面更新的答案,我没有尝试创建一个 应用程序密码 并同意 帐户:读/写 在bitbucket中,它可以工作。我运行它时使用:

    curl -v -u myuser:my-generated-app-password -X POST  \
    -H "Content-Type: application/json" \
    -d '{"key": "ssh-rsa AAA....ro"}' \
    https://api.bitbucket.org/2.0/users/myuser/ssh-keys
    
    1 回复  |  直到 6 年前
        1
  •  9
  •   Jim Redmond    7 年前

    退房 https://developer.atlassian.com/bitbucket/api/2/reference/resource/users/%7Busername%7D/ssh-keys#post 相反,这是bitbucketcloud文档来完成您想要做的事情。你的网址将更像 https://api.bitbucket.org/2.0/users/[your-account]/ssh-keys .

    编辑:您收到的错误表明存在问题:您需要从现有会话(即从GUI)中进行调用、使用密码或使用 app password curl -u myuser:myapppassword -X POST -H "Content-Type: application/json" -d '{"key": "key content goes here"}' https://api.bitbucket.org/2.0/users/myuser/ssh-keys .