Github api returns bad credentials even with oauth token
Asked Answered
B

2

14

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?

Bolanger answered 3/2, 2020 at 12:41 Comment(0)
B
7

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

Bolanger answered 6/2, 2020 at 15:24 Comment(1)
Can you/someone give some supporting code snippet and clarification on this answerMontalvo
A
4

The following curl command works: curl -u your_git_name:your_personal_access_token https://api.github.com/user

Ancell answered 4/2, 2020 at 15:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.