How to add ssh-keys via GitHub's v3 API? -
i'm trying add ssh key via github's v3 api, doesn't seem working.
what i'm doing based on instructions given here.
more specifically, i'm using following:
key=$( cat ~/.ssh/id_rsa.pub ) title=${key/* } # '/* ' above deletes every character in $key , including last # space. json=$( printf '{"title": "%s", "key": "%s"}' "$title" "$key" ) token=$( cat /path/to/tokenfile ) curl -s -d "$json" "https://api.github.com/user/keys?access_token=$token"
when run above, response is:
{ "message": "not found" }
...and, sure enough, when check in github account, $key
not among ssh-keys listed1.
what doing wrong?
additional details
i same "message": "not found"
response if run
curl -s "https://api.github.com/user/keys?access_token=$token"
if replace -s
above -i
see that, indeed, returned status 404 not found
. , yet, returned status for
curl -i "https://api.github.com/user/keys"
is 401 unauthorized
.
1 know access token in $token
fine, , therefore not reason "message": "not found"
response, because
curl -s "https://api.github.com/user/repos?access_token=$token"
returns correct information, and
curl -s "https://api.github.com/user/repos"
returns
{ "message": "requires authentication" }
does access token have "user" scope? relevant excerpt docs:
management of public keys via api requires authenticated through basic auth, or oauth ‘user’ scope.
if token not have "user" scope, 404 response message of "not found".
to see scopes associated tokens, use "authorizations" api:
curl -u <username> https://api.github.com/authorizations
in example response below, first authorization has "user" scope, second 1 not.
enter code here [ { "id": 123, "url": "https://api.github.com/authorizations/123", "app": { "name": "foo", "url": "https://foo.example.com/", "client_id": "redacted-id-1" }, "token": "redacted-token-1", "note": null, "note_url": null, "created_at": "2013-02-18t18:24:00z", "updated_at": "2013-05-06t14:17:00z", "scopes": [ "repo", "user" ] }, { "id": 456, "url": "https://api.github.com/authorizations/456", "app": { "name": "bar", "url": "https://bar.example.com/", "client_id": "redacted-id-2" }, "token": "redacted-token-2", "note": "for stuff", "note_url": null, "created_at": "2013-04-16t12:20:00z", "updated_at": "2013-05-13t21:28:00z", "scopes": [ "public_repo" ] } ]
if determine source of problem, can resolve in 1 of 2 ways:
- create new token has "user" scope, or
- update existing token add "user" scope it:
"add_scopes": [ "user" ]
Comments
Post a Comment