From 5a1fbe4ad805c5d9ee83a4fe5c94f4742787a368 Mon Sep 17 00:00:00 2001 From: Chris Coveney Date: Wed, 18 Nov 2026 14:16:13 -0800 Subject: [PATCH] DEV-446: Read Apple sign-in tokens from the URL fragment - oauth-callback takes the Apple access and refresh tokens from the URL fragment, which never reaches a server, log or Referer - Falls back to the old ?code=&refresh_token= query, so it works before and after the API switches - Clears the tokens from the address bar and history right away - Stores the Apple refresh token instead of dropping it, so Apple web sessions renew like Google and GitHub ones --- src/app/oauth-callback/page.tsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/app/oauth-callback/page.tsx b/src/app/oauth-callback/page.tsx index 7027b67..23015bb 100644 --- a/src/app/oauth-callback/page.tsx +++ b/src/app/oauth-callback/page.tsx @@ -106,21 +106,25 @@ function OAuthCallbackContent() { return; } - // Handle Apple OAuth differently since it redirects with token as URL parameter + // Apple: the API hands the tokens over in the URL fragment, which never + // reaches a server, a log or a Referer. Older API pages put them in the + // query (?code=&refresh_token=), so read both, then drop them from the + // address bar and history. if (provider === "apple") { - const token = searchParams.get("code"); + const fragment = new URLSearchParams(window.location.hash.slice(1)); + const token = fragment.get("access_token") ?? searchParams.get("code"); + const refreshToken = + fragment.get("refresh_token") ?? searchParams.get("refresh_token"); + window.history.replaceState(null, "", window.location.pathname); if (!token) { setErrorMessage("Missing token from Apple OAuth."); return; } - // Store the token localStorage.setItem("token", token); - storeRefreshToken(null); + storeRefreshToken(refreshToken); - // Handle redirect for both native and regular modes - // Apple OAuth doesn't provide a refresh_token here - await handleAppRedirect(token, null, cliState, mode); + await handleAppRedirect(token, refreshToken || null, cliState, mode); return; }