Skip to content

Conversation

@akirk
Copy link
Member

@akirk akirk commented Jan 25, 2026

Motivation for the change, related issues

When using blueprints that reference private GitHub repositories, the OAuth authentication flow has several issues:

  1. Hash blueprints are lost: URL fragments (e.g., #{"steps":...}) are not sent to servers in HTTP requests, so they're lost during the OAuth redirect to GitHub and back.

  2. Token not used after OAuth: The createGitAuthHeaders() function captured the OAuth token at creation time, but the token is only available after the OAuth redirect completes. It still works here because the page reloads after OAuth, and the token is acquired before boot starts on the fresh page. The bug would only show when we remove the blueprint parameters as we do in personal-wp.

  1. User loads page with private repo blueprint
  2. Boot fails with GitAuthenticationError (no token)
  3. Auth modal shown, user authenticates
  4. GitHub redirects back with ?code=...
  5. Page loads fresh - acquireOAuthTokenIfNeeded() runs at module import time
  6. Token is exchanged and stored before React renders
  7. Boot starts, createGitAuthHeaders() is called - token already exists
  8. Blueprint succeeds
  1. Client setup runs after errors: When startPlaygroundWeb throws an error (e.g., GitAuthenticationError), the catch block handles it but execution continues to run client setup code, which shouldn't happen for failed boots.

Implementation details

  1. Add buildOAuthRedirectUrl(): Converts URL fragment blueprints to blueprint-url query parameters before the OAuth redirect, preserving the blueprint through the round-trip.

  2. Fix token capture timing: Move token retrieval inside the returned function so it's captured at call time, not creation time.

  3. Add early return in catch block: Prevent client setup code from running after boot errors.

Testing Instructions (or ideally a Blueprint)

  1. Navigate to the Playground with a hash blueprint referencing a private GitHub repo:
    https://playground.wordpress.net/#{"steps":[{"step":"installPlugin","pluginData":{"resource":"url","url":"https://github.com/user/private-repo/archive/refs/heads/main.zip"}}]}
    
  2. Observe the GitHub auth modal appears
  3. Click "Connect your GitHub account" and complete the OAuth flow
  4. After redirect, verify the blueprint is preserved and applied with authentication

akirk added 2 commits January 25, 2026 09:59
When startPlaygroundWeb throws an error (e.g., GitAuthenticationError),
the catch block handles it but execution continues past the catch to
run client setup code (setupPostMessageRelay, addClientInfo, etc.).

This happens because the `playground` variable may already be set via
the onClientConnected callback before the error is thrown, so the
`if (!playground) return` check doesn't prevent continued execution.

Adding an early return at the end of the catch block ensures we don't
attempt to set up a client that failed to boot properly.
…n at call time

Two fixes for the GitHub OAuth flow:

1. buildOAuthRedirectUrl: Converts URL fragment blueprints (e.g., #{"steps":...})
   to blueprint-url query parameters before the OAuth redirect. URL fragments
   are not sent to servers in HTTP requests, so they would be lost during the
   OAuth redirect flow.

2. createGitAuthHeaders: Moves token retrieval inside the returned function
   so the token is captured at call time, not at creation time. This ensures
   the OAuth token acquired during the redirect flow is used for subsequent
   GitHub API requests.
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

Successfully merging this pull request may close these issues.

2 participants