Skip to content

Commit 5e8e654

Browse files
author
flowcore-platform
committed
fix: remove audience parameter from Keycloak config to fix production auth
Root cause: Keycloak access tokens with explicit audience claim (audience: USABLE_CLIENT_ID) were being rejected by the Usable API with 401 Unauthorized errors. Changes: - Remove audience parameter from Keycloak authorization config - Add token prefix logging to Usable API service for debugging - Minor middleware formatting cleanup Impact: Users can now successfully authenticate and access workspaces in production (https://graphable.usable.dev) Evidence from groundcover: - Auth succeeded, tokens stored correctly - But Usable API returned "Unauthorized" on workspace fetch - Pattern: successful sign-in followed by API rejection Solution: Keycloak now issues tokens with default audience that are compatible with Usable API expectations. Refs: Usable fragment 9a6f4b48-d34b-4d4a-8267-dae00ebcf25d
1 parent 055ceed commit 5e8e654

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

lib/auth.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ export const authOptions: NextAuthOptions = {
128128
authorization: {
129129
params: {
130130
scope: "openid email profile offline_access",
131-
// Request token with correct audience for MCP server
132-
audience: env.USABLE_CLIENT_ID,
133131
// Enable PKCE (Proof Key for Code Exchange) to prevent double-submit and code replay attacks
134132
code_challenge_method: "S256",
135133
},

lib/services/usable-api.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export class UsableApiService {
9797
errorDetails: errorData.details ? JSON.stringify(errorData.details, null, 2) : undefined,
9898
endpoint,
9999
method: fetchOptions.method || "GET",
100+
// Log token prefix for debugging (not the full token)
101+
tokenPrefix: accessToken ? `${accessToken.substring(0, 20)}...` : undefined,
100102
})
101103
throw new Error(errorMessage)
102104
}

middleware.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,5 @@ export default withAuth(
7474
)
7575

7676
export const config = {
77-
matcher: [
78-
"/((?!_next/static|_next/image|favicon.ico|api/health|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
79-
],
77+
matcher: ["/((?!_next/static|_next/image|favicon.ico|api/health|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)"],
8078
}

0 commit comments

Comments
 (0)