Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect Repository fails - 401 Unauthorized request to GitHub API #925

Closed
dvdvnl opened this issue Apr 9, 2019 · 3 comments
Closed

Connect Repository fails - 401 Unauthorized request to GitHub API #925

dvdvnl opened this issue Apr 9, 2019 · 3 comments

Comments

@dvdvnl
Copy link

dvdvnl commented Apr 9, 2019

Description

In some cases the possibility to push code from a StackBlitz application to GitHub does not work. In my particular case this happened after I needed to clean up (i.e. remove all) my authorized OAuth apps on GitHub.

This included the StackBlitz app as well, so that I had to re-authorize access to my GitHub account the next time I wanted to sign in to StackBlitz. While that worked there was no second authorization request that lets StackBlitz access my repositories as well (like the first time). After that my attempts to push a StackBlitz application to GitHub failed.

Reproduction steps:

  1. Sign in to StackBlitz
  2. Allow access to your GitHub account for the StackBlitz app (OAuth)
  3. Create a new application on StackBlitz
  4. Click on "Connect Repository" and "Create Repo & Push"
  5. The repository is created on GitHub
  6. Head over to the authorized OAuth apps on GitHub and remove the StackBlitz app
  7. Repeat steps 1. to 4.
  8. The "Connecting..." message will spin forever due to the fact that the POST XHR to https://api.github.com/user/repos returns a 401 Unauthorized

GitHub's response in step 8 is:

documentation_url: "https://developer.github.com/v3"
message: "Bad credentials"

Hypothesis (wild guess)

  • The StackBlitz app saves the OAuth token the first time a user grants access to their GitHub account.
  • Later, when a user wants to push code from StackBlitz to GitHub (the first time), the app requests additional rights (access to repositories) and stores a flag that states that those rights were granted.
  • After that the OAuth app is removed from GitHub and the next time a user tries to sign in to StackBlitz the stored token is invalid. Hence StackBlitz requests access to a user's GitHub account again.
  • Access is granted again, however the StackBlitz app is still not allowed to access the repositories. But StackBlitz still has the flag that states that it has the rights to do so.
  • So the XHR is executed, leading to a 401. But there's no error handler in StackBlitz to reset the flag.
@sivathangeswaran
Copy link

Anyone solved this problem or any workarounds?

@sunildivyam
Copy link

I am also having same issue and tried with firefox and chrome, and also disabling all pop-up blockers.
But no success. I also could not find any useful reply from anyone.
Anyone has any solution to this problem?

@kc0tlh
Copy link
Collaborator

kc0tlh commented Aug 30, 2023

This issue is now resolved in our new VS Code editor! Additional details in Github issue #2473

@kc0tlh kc0tlh closed this as completed Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants