0

I'm building a web app that integrates with GitHub API (authentication). I'm trying to fetch the user's repositories both public and private. But both without accessToken and with accessToken return public repos only.

  1. authentication

  const provider = new GithubAuthProvider();
  provider.addScope('repo');

  const PopupSignIn = async () => {
     const result = await signInWithPopup(auth, provider);
     const credential = GithubAuthProvider.credentialFromResult(result);
     setToken(credential.accessToken)
     return credential;
  };
  1. fetching repositories
    user here is the auth credential got from getAuth()
PopupSignIn().then(() => {
   fetch(
      `https://api.github.com/users/${user.reloadUserInfo.screenName}/repos`,
      { headers: { authorization: token } }
   )
});
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
angel_dust
  • 121
  • 2
  • 10
  • 1
    Does the API work as expected if you hand-craft the request in, e.g., Postman? If so, is there any difference between that request and the request from your code as captured by, e.g., Fiddler? My initial thought is that `token` may be just the token, when it should be `Token: {token}`. – Stephen Cleary Apr 14 '22 at 14:42
  • @StephenCleary I added ```Token: {my_token}``` to my headers in fetch request. Now I got CORS error. – angel_dust Apr 14 '22 at 16:21

0 Answers0