Skip to content

Commit 2b47266

Browse files
committed
fix: alias /x/authkit/users/authenticate for SDK refresh token flow
The AuthKit SDK sends refresh_token grants to /x/authkit/users/authenticate rather than /user_management/authenticate. Register the same handler on both paths so the SDK's refreshTokens() and switchToOrganization() work against the emulator.
1 parent 71a08b6 commit 2b47266

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/emulate/core/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function createServer(plugin: ServicePlugin, options: ServerOptions = {})
4848
}
4949
return authMiddleware(apiKeys)(c, next);
5050
});
51+
app.use('/x/authkit/*', authMiddleware(apiKeys));
5152
app.use('/organizations', authMiddleware(apiKeys));
5253
app.use('/organizations/*', authMiddleware(apiKeys));
5354
app.use('/organization_memberships', authMiddleware(apiKeys));

src/emulate/workos/routes/auth.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ export function authRoutes(ctx: RouteContext): void {
9696
return c.json(formatDeviceAuthorization(deviceAuth));
9797
});
9898

99-
app.post('/user_management/authenticate', async (c) => {
99+
// AuthKit SDK uses /x/authkit/users/authenticate for the same flow
100+
const authenticateHandler = async (c: any) => {
100101
const body = await parseJsonBody(c);
101102
const grantType = body.grant_type as string | undefined;
102103
const clientId = body.client_id as string | undefined;
@@ -414,5 +415,8 @@ export function authRoutes(ctx: RouteContext): void {
414415
sealed_session: sealedSession,
415416
impersonator: updatedUser.impersonator ?? undefined,
416417
});
417-
});
418+
};
419+
420+
app.post('/user_management/authenticate', authenticateHandler);
421+
app.post('/x/authkit/users/authenticate', authenticateHandler);
418422
}

0 commit comments

Comments
 (0)