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

Fix creating SWA in browser CodeSpaces #841

Merged
merged 1 commit into from
Jun 26, 2023
Merged

Conversation

alexweininger
Copy link
Member

Fixes #827

Make sure to read #827 (comment) for context.

Take my explanation with a grain of salt because it's only based on my investigation and assumptions on how browser-based CodeSpaces work. I haven't confirmed any of this with VS Code maintainers.

I believe this is a VS Code bug. I filed microsoft/vscode#185915


When connecting to a CodeSpace in your browser you're on a GitHub hosted link and authenticated through GitHub via the "GitHub CodeSpaces" GitHub App. See your authorized GitHub Apps
image

In all other scenarios, VS Code uses OAuth to authenticate with GitHub.
image

When you connect to a CodeSpace in your browser, without taking any actions, VS Code already shows that you're signed into GitHub. I'm guessing that this is a reflection of the default user-to-server token (ghu_) being present. For some reason, VS Code returns this token for the scopes we request in Static Web Apps (repo, workflow, user:email, read:user).

The SWA service cannot use the returned ghu_ token to create a Static Web App (it probably needs to in the future...).

Adding any additional scopes actually makes VS Code return a gho_ token. And GitHub doesn't seem to complain about asking for random non-existent scopes. My workaround is to request a token with an additional made up scope if we see get a ghu_ token from VS Code. In my testing this always results in VS Code returning a gho_ token and everything just works! This has also been confirmed by other users.

@alexweininger alexweininger requested a review from a team as a code owner June 23, 2023 00:48
Copy link
Member

@nturinski nturinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a crazy bug... Can't believe you figured that out.

@alexweininger alexweininger merged commit 26523ac into main Jun 26, 2023
@alexweininger alexweininger deleted the alex/olive-warbler branch June 26, 2023 22:01
@microsoft microsoft locked and limited conversation to collaborators Aug 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

An error "RepositoryToken is invalid..." occurs when creating a static web app
3 participants