···4040 dpopTokenProvided: !!dpopToken
4141 });
42424343- // Use the provided PDS endpoint or default to Bluesky's
4444- // CRITICAL FIX: For third-party PDS, always use bsky.social for token requests
4343+ // CRITICAL FIX: Use the correct token endpoint based on PDS type
4444+ // - For bsky.network PDSes: always use bsky.social for token exchange
4545+ // - For third-party PDSes: use their own endpoint for token exchange
4546 let authServer = pdsEndpoint || DEFAULT_AUTH_SERVER;
4646- if (pdsEndpoint && !pdsEndpoint.includes('bsky.social')) {
4747- console.log(`[TOKEN ROUTE] Redirecting token request to bsky.social for third-party PDS: ${pdsEndpoint}`);
4747+4848+ if (pdsEndpoint) {
4949+ // If it's a bsky.network PDS, use bsky.social
5050+ if (pdsEndpoint.includes('bsky.network')) {
5151+ console.log(`[TOKEN ROUTE] Using bsky.social for bsky.network PDS: ${pdsEndpoint}`);
5252+ authServer = DEFAULT_AUTH_SERVER;
5353+ } else if (pdsEndpoint.includes('bsky.social')) {
5454+ // Already using bsky.social
5555+ console.log(`[TOKEN ROUTE] Using bsky.social endpoint directly`);
5656+ } else {
5757+ // For third-party PDSes, use their own endpoint for token exchange
5858+ console.log(`[TOKEN ROUTE] Using third-party PDS's own endpoint for token exchange: ${pdsEndpoint}`);
5959+ // Keep authServer as the original PDS endpoint
6060+ }
6161+ } else {
6262+ // Default to bsky.social if no PDS endpoint provided
6363+ console.log(`[TOKEN ROUTE] No PDS endpoint provided, using default: ${DEFAULT_AUTH_SERVER}`);
4864 authServer = DEFAULT_AUTH_SERVER;
4965 }
5066···7894 code_verifier: codeVerifier
7995 });
80968181- // For third-party PDS, add the 'resource' AND 'issuer' parameters
8282- // These are CRITICAL for the token exchange to work with third-party PDS servers
9797+ // CRITICAL FIX: We only need to add cross-domain parameters when using bsky.social
9898+ // for a third-party PDS's code exchange (which we're no longer doing)
9999+ // But we'll keep this logic in case it's needed for specific PDS implementations
83100 if (originalPdsEndpoint && originalPdsEndpoint !== authServer) {
8484- console.log(`[TOKEN ROUTE] Adding resource parameter for third-party PDS: ${originalPdsEndpoint}`);
8585- formData.append('resource', originalPdsEndpoint);
8686-8787- // Add the issuer parameter which is required for cross-domain OAuth
8888- console.log(`[TOKEN ROUTE] Adding issuer parameter for third-party PDS: ${originalPdsEndpoint}`);
8989- formData.append('issuer', originalPdsEndpoint);
101101+ console.log(`[TOKEN ROUTE] Cross-domain token exchange detected`);
102102+ console.log(`[TOKEN ROUTE] Not adding cross-domain parameters as we're using direct PDS endpoints`);
90103 }
9110492105 // Log the complete request for debugging
+16-8
app/src/app/auth/callback/page.tsx
···165165 console.log('Exchanging code for token...');
166166 let tokenResponse;
167167 try {
168168- // CRITICAL FIX: For third-party PDS, we need special handling for token exchange
168168+ // CRITICAL FIX: Token exchange approach depends on PDS type
169169 let authServer = storedAuthServer || 'https://bsky.social';
170170 let tokenPdsEndpoint = storedPdsEndpoint;
171171···177177 // Store this for later use
178178 storeAuthData('pds_endpoint', iss);
179179180180- // For third-party PDS, we need to ensure we're using the right auth server
181181- if (!iss.includes('bsky.social')) {
182182- // Always use bsky.social for token exchange with third-party PDS
180180+ // Choose the right auth server based on PDS type
181181+ if (iss.includes('bsky.network')) {
182182+ // For bsky.network PDSes, always use bsky.social
183183 authServer = 'https://bsky.social';
184184- console.log('Third-party PDS detected, using bsky.social as auth server');
185185-186186- // Also store the auth server
187187- storeAuthData('auth_server', authServer);
184184+ console.log('bsky.network PDS detected, using bsky.social as auth server');
185185+ } else if (iss.includes('bsky.social')) {
186186+ // Already using bsky.social
187187+ authServer = 'https://bsky.social';
188188+ console.log('bsky.social detected, using it directly as auth server');
189189+ } else {
190190+ // For third-party PDSes, use their own endpoint for token exchange
191191+ authServer = iss;
192192+ console.log('Third-party PDS detected, using its own endpoint as auth server:', iss);
188193 }
194194+195195+ // Store the auth server
196196+ storeAuthData('auth_server', authServer);
189197 }
190198191199 console.log('Authentication servers:', {