lundi 13 août 2018

GitHub OAuth App - getting token

I have an simple web app I'm testing on localhost (using http-server) in which I'm trying to authorise it following the GitHub tutorial.

I was able to redirect to GitHub page so the user can login there and get the temporary code returned from GitHub as query parameter.

Yet I can't get auth token because every time I send a POST request with all the required data I'm getting CORB error.

The code I'm using to do that:

const getGitHubToken = async code => {
    return await fetch(authData.accessTokenURL, {
        method: 'POST',
        body: {
            client_id: authData.client_id,
            client_secret: authData.client_secret,
            code
        },
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    });
};

So my questions are:

  • why isn't it working
  • is it safe to keep client_id and client_secret on client side
  • any suggestions if it's good idea to apply this approach when my aim is to create an app able to query GitHub API (general stats, public repos)



Aucun commentaire:

Enregistrer un commentaire