u12*_*123 5 rest curl bitbucket
我有一个bitbucket云帐户.在:https://id.atlassian.com/manage/api-tokens我生成了一个API令牌,我试图在REST调用中将公共SSH密钥上传到我的帐户.基于:
我试过了:
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
Run Code Online (Sandbox Code Playgroud)
但当我跑步时,我得到:
{"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}
Run Code Online (Sandbox Code Playgroud)
我试图重新创建令牌并重新运行上面的命令 - 使用新令牌 - 但我得到了同样的错误.
有什么建议?
根据以下答案和链接,我现在尝试:
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
Run Code Online (Sandbox Code Playgroud)
但我得到完全相同的错误:
{"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}
Run Code Online (Sandbox Code Playgroud)
所以仍然没有运气.如果我访问:
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"
Run Code Online (Sandbox Code Playgroud)
编辑/答案:根据下面更新的答案,我没有尝试创建一个应用程序密码并授予它帐户:读取/写入 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
Run Code Online (Sandbox Code Playgroud)
您正在查看Bitbucket Server文档,但使用的是Bitbucket Cloud.(赠品:文档路径中的"bitbucket-server"部分,以及您推送密钥的路径中的"bitbucket.org".)
请查看https://developer.atlassian.com/bitbucket/api/2/reference/resource/users/%7Busername%7D/ssh-keys#post - 这是Bitbucket Cloud文档,可以执行您要执行的操作.你的网址会更像https://api.bitbucket.org/2.0/users/[your-account]/ssh-keys
.
编辑:您收到的错误表明问题:您需要从现有会话(即从GUI)进行该调用,使用您的密码或使用应用程序密码.我建议使用应用程序密码,因为它的作用域是一次性的,不会让你登录到GUI.你的卷曲调用就变成了类似的东西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
.
归档时间: |
|
查看次数: |
488 次 |
最近记录: |