Repository navigation
fix(integrations): decode base64url oauth state in the callback - #1654
Merged
Merged
Conversation
TikTok encodes the OAuth state as base64url, but the integrations callback decoded it with atob, which rejects "-" and "_". Whenever the encoded state contained them the callback returned 404, so connecting TikTok failed for most workspaces. Decode with Node's base64url decoder, which accepts both base64url and the standard base64 the other integrations produce with btoa. Reported in #1572 (comment 6650507443). Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 of 6 tasks
hello-jackytruong
referenced
this pull request
in hello-jackytruong/ChatWorkAI
Nov 22, 2026
TikTok encodes the OAuth state as base64url, but the integrations callback decoded it with atob, which rejects "-" and "_". Whenever the encoded state contained them the callback returned 404, so connecting TikTok failed for most workspaces. Decode with Node's base64url decoder, which accepts both base64url and the standard base64 the other integrations produce with btoa. Reported in #1572 (comment 6650507443). Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the TikTok connect flow returning 404 on the OAuth callback, reported in #1572 (comment).
stateas base64url (integrations/tiktok/src/apis/auth.ts), which uses-and_.atob, which rejects-and_("Invalid character") →notFound()..../settings/channels?channel=tiktokreferer, the encoded state contains those characters practically every time (2000/2000 in a local run), so connecting TikTok failed for most workspaces.Change
decodeOAuthState()inapps/builder/src/lib/oauth-state.ts: decodes withBuffer.from(raw, "base64url"), which accepts both base64url (TikTok) and the standard base64 the other integrations produce withbtoa(Zalo, Google Sheets/Calendar, Instagram, WhatsApp).atob. Connect-session states ({sessionId}.{nonce}) are unaffected — they are dispatched before this parse.Test plan
apps/builder/__tests__/oauth-state-decode.test.ts: base64url state with-/_, standard base64 state, percent-encoded state, invalid state throwsoauth-callback-connect-session,oauth-reconnect-callback) passultracite checkon changed files,check:invariants,pnpm check-types --filter builder🤖 Generated with Claude Code