0

Trying to get a simple webpage running to get Github oauth access token.

Code to get "code":

window.location.replace("https://github.com/login/oauth/authorize?client_id=" + ClientID);

Code to get "access_token":

var data = {
    client_id: ClientID,
    client_secret: ClientSecret,
    code: code
};
$.ajax({
    url: "https://github.com/login/oauth/access_token",
    type: "post",
    data: data,
    dataType: "json",
    headers: {
        "Access-Control-Allow-Origin": "*"
    },
    success: function() { alert("Success"); },
    error: function() { alert('Failed!'); }
});

In the project folder, I ran the python -m http.server to start server.

In Github Application page, "Authorization callback URL" is "http://localhost:8000".

I'm able to get the "code", but not the "access_token". The error I got from the jQuery ajax post is:

HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(XHR)OPTIONS - https://github.com/login/oauth/access_token

I suspect one of the following things I did was wrong:

  • python command to start local server
  • wrong header for the ajax post
  • wrong way to call the URL

Appreciate your suggestions and help!

Vincent Li
  • 55
  • 1
  • 6

0 Answers0