githuboauthgithub-apigithub-oauth

Github api returns bad credentials even with oauth token


update: even such a request get bad credential ==>

curl -H "Authorization: token [token]" https://api.github.com

===============

I made a request for GitHub OAuth like this in my iOS app:

URL: https://github.com/login/oauth/authorize,
params: client_id: ****, redirect_uri: app_url, scope: "repo", state: "0"

After redirection from Safari I get a code. I need to access to two things:

  1. User data, like email and etc. Also updating user data.
  2. List of repositories and commits in public and private repos.

I make following requests:

URL: https://api.github.com/user, get and patch Header: Authorization: token [code]

URL: https://api.github.com/repos/:username/:repoName
Header: Authorization: token [code]

But unfortunately, I get the following error:

401, Unauthorized
{
    "message": "Bad credentials",
    "documentation_url": "https://developer.github.com/v3"
}

What is the problem and how can I solve it?


Solution

  • As it is said in this blob (NOT the main documentation) you have to exchange token (which is temporary) with a bearer token via this api:

    the main api

    Here comes the documentation for others: Github blob documentation