Fix creating SWA in browser CodeSpaces #841
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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](https://private-user-images.githubusercontent.com/12476526/248106634-7c01d128-59eb-40cd-90e3-33f52e7c8515.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwOTk5MTgsIm5iZiI6MTczOTA5OTYxOCwicGF0aCI6Ii8xMjQ3NjUyNi8yNDgxMDY2MzQtN2MwMWQxMjgtNTllYi00MGNkLTkwZTMtMzNmNTJlN2M4NTE1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDExMTMzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEwZjE5YmE2Y2ZkMzlmNWVmY2YyN2Y0ZGM0MmQ3ZjI2YTRjMTY3NDNmOGJiYjViMWFkNWQ3NzE5NjVkYWU3NTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Q_CS9vAM0AIyVWX0hHWVSP7ouzVADkyFN8-gKa3K7AI)
In all other scenarios, VS Code uses OAuth to authenticate with GitHub.
![image](https://private-user-images.githubusercontent.com/12476526/248106583-aa0dc6a0-a995-4698-b139-55ab5c5ee76d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwOTk5MTgsIm5iZiI6MTczOTA5OTYxOCwicGF0aCI6Ii8xMjQ3NjUyNi8yNDgxMDY1ODMtYWEwZGM2YTAtYTk5NS00Njk4LWIxMzktNTVhYjVjNWVlNzZkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDExMTMzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNjOWJjZjRkMjJhZDY4MjUwYTI4ZDkxNTIzYjI5NjcyNjRhYjQ5YTE3MDk3ZjBjMWJiYzQxZDNiNmMxMmY2YjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.l7zJUUxk11HtGdUNpMmExf77ojf4JklCy-eVKzBv0qQ)
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 aghu_
token from VS Code. In my testing this always results in VS Code returning agho_
token and everything just works! This has also been confirmed by other users.