Sunday, September 4, 2022

[SOLVED] Github api request returning bad credentials even with admin privledged oauth token

Issue

I am trying to make a call https://api.github.com/repos/OWNER/REPO/actions/runners/registration-token with an users personal access token that has repo permissions.

To do so I am testing with:

curl -I -X POST -H "Authorization: token <OAUTH_TOKEN> Accept: application/vnd.github.v3+json" https://api.github.com/repos/<owner>/<repo-name>/actions/runners/registration-token which gives me Bad Credentials error

curl -I -H "Authorization: token <OAUTH_TOKEN>" https://api.github.com/users/<USER_NAME> ->

x-oauth-scopes: repo
x-accepted-oauth-scopes: 

According to this: https://docs.github.com/en/rest/actions/self-hosted-runners I need to provide an oauth token with repo access.

If I curl the user curl -H "Authorization: token <OAUTH_REPO_TOKEN>" https://api.github.com/users/<USER>/repos -> []. But if I go to the repo and check settings -> Collaborators And Teams, the user is listed as part of the team with admin privledges, and I have also added an entry for the user directly.

Is there something I am missing? What permissions do I need to add to fix this?


Solution

I needed to call the API with a user name as well. For example: curl -I -X POST -u <USER>:<OAUTH_REPO_TOKEN> -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/<owner>/<repo-name>/actions/runners/registration-token. Passing a -v option reveals that it was not setting a username, and causing github to reject the call.



Answered By - Niru
Answer Checked By - David Goodson (WPSolving Volunteer)