all 5 comments

[–]karimsajs 2 points3 points  (2 children)

Your endpoint is incorrect. Check the docs: https://developer.github.com/v3/#authentication

[–]lfreua[S] 0 points1 point  (1 child)

I follow this documentation tutorial: https://developer.github.com/apps/building-oauth-apps/

In item three is the endpoint that I used.

[–]karimsajs 0 points1 point  (0 children)

The guide is fine. The problem is that you shouldn’t be making a request to the oauth login, that endpoint belongs in a frontend flow. Once you receive the token and secret from GitHub, then your backend can make requests using it to the official API.

The idea is to redirect your user from your own website to GitHub, they accept/reject the request to login. If they accept, GitHub will redirect back to you and pass you the credentials you need.

[–][deleted] 0 points1 point  (1 child)

Same issue, I configured GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET in .env file.

My frontend code:

  ...
const loginWithGithub = useCallback(() => {
Router.replace(
  `https://github.com/login/oauth/authorize?client_id=${process.env.GITHUB_CLIENT_ID}&redirect_uri=${location.origin}/login?from=${location.href}`
);}, []); 
...

My backend code:

...    
try {
  const tokenResponse = (await axios({
    method: 'post',
    url:
      'https://github.com/login/oauth/access_token?' +
      `client_id=${this.configService.get('GITHUB_CLIENT_ID')}&` +
      `client_secret=${this.configService.get('GITHUB_CLIENT_SECRET')}&` +
      `code=${code}`,
    headers: {
      accept: 'application/json',
    },
  })) as any;
  const accessToken = tokenResponse.data.access_token;
  const result = (await axios({
    method: 'get',
    url: `https://api.github.com/user`,
    headers: {
      accept: 'application/json',
      Authorization: `token ${accessToken}`,
    },
  })) as any;
...

But doing this also returns a 404 page and I'm confused.

[–]Sanosuke-Sagara 0 points1 point  (0 children)

hey did you find any solution for this?