Skip to content

Commit 8023564

Browse files
committed
fix(tests): Fix test-confidential-client.js to match Better Auth response format
Problem: - test-confidential-client.js expected 302 redirect with Location header - Better Auth returns 200 with JSON body containing redirect URL - Wrong client secret (test-secret-key-change-in-production) - Wrong redirect URI (/callback vs /auth/callback) Solution: - Updated to handle Better Auth's JSON response format - Extract code from body.url using regex match - Updated CLIENT_SECRET to match trusted-clients.ts - Updated REDIRECT_URI to match trusted-clients.ts Result: - test-confidential-client.js should now pass - ALL API tests should pass! 🎉 🤖 Generated with Claude Code
1 parent 03679ea commit 8023564

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

auth-server/tests/test-confidential-client.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*/
1111

1212
const CLIENT_ID = "robolearn-confidential-client";
13-
const CLIENT_SECRET = "test-secret-key-change-in-production";
13+
const CLIENT_SECRET = "robolearn-confidential-secret-for-testing-only";
1414
const AUTH_SERVER = "http://localhost:3001";
15-
const REDIRECT_URI = "http://localhost:8000/callback"; // FastAPI would listen here
15+
const REDIRECT_URI = "http://localhost:8000/auth/callback"; // Must match trusted-clients.ts
1616

1717
// Test user credentials
1818
const TEST_USER = {
@@ -65,12 +65,20 @@ async function testConfidentialClient() {
6565
redirect: "manual"
6666
});
6767

68-
const location = authResponse.headers.get("location");
69-
if (!location || !location.includes("code=")) {
68+
// Better Auth returns JSON with redirect URL (not a 302 redirect)
69+
let code;
70+
if (authResponse.status === 200) {
71+
const body = await authResponse.json();
72+
if (body.redirect && body.url) {
73+
const match = body.url.match(/code=([^&]+)/);
74+
if (match) code = match[1];
75+
}
76+
}
77+
78+
if (!code) {
7079
throw new Error("No authorization code in redirect");
7180
}
7281

73-
const code = new URL(location, REDIRECT_URI).searchParams.get("code");
7482
console.log("✓ Authorization code received:", code.substring(0, 20) + "...\n");
7583

7684
// Step 4: Exchange code for tokens using client secret

0 commit comments

Comments
 (0)