fix(client/auth): propagate saveTokens errors after refresh#2053
Conversation
Closes modelcontextprotocol#2034 Signed-off-by: SAY-5 <say.apm35@gmail.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
|
The |
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Closes #2034
The
try { refreshAuthorization(...); saveTokens(...); } catch (error)block inauth()was wide enough to swallowsaveTokens()failures (any non-OAuthError, plusServerError). With rotating refresh tokens, that loses the freshly minted refresh token while the AS has already invalidated the old one, leaving the client unable to recover.Split the block: the
try/catchnow wraps onlyrefreshAuthorization, where fall-through to a fresh authorization flow is the intended recovery.saveTokensruns after the catch on a separate, unguarded path so its errors propagate to the caller.Added a vitest regression test under
OAuth Authorization > auth functionthat mockssaveTokensto reject, asserts the rejection bubbles to theauth()caller, and assertsredirectToAuthorizationis never reached. The test fails onmainand passes with this change. Fullpackages/clientsuite (365 tests) passes;pnpm lintclean.