From 649bcae6d38bc44fa19090df5b9ee4c739e398cb Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Thu, 11 Jul 2024 14:50:49 -0700 Subject: [PATCH] Plumb error through to auth page (#221511) plumb error through to auth page --- .../src/node/authServer.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/extensions/microsoft-authentication/src/node/authServer.ts b/extensions/microsoft-authentication/src/node/authServer.ts index de08c6fca0f..2d6a8d03861 100644 --- a/extensions/microsoft-authentication/src/node/authServer.ts +++ b/extensions/microsoft-authentication/src/node/authServer.ts @@ -110,20 +110,29 @@ export class LoopbackAuthServer implements ILoopbackServer { const code = reqUrl.searchParams.get('code') ?? undefined; const state = reqUrl.searchParams.get('state') ?? undefined; const nonce = (reqUrl.searchParams.get('nonce') ?? '').replace(/ /g, '+'); + const error = reqUrl.searchParams.get('error') ?? undefined; + if (error) { + res.writeHead(302, { location: `/?error=${reqUrl.searchParams.get('error_description')}` }); + res.end(); + deferred.reject(new Error(error)); + break; + } if (!code || !state || !nonce) { res.writeHead(400); res.end(); - return; + break; } if (this.state !== state) { res.writeHead(302, { location: `/?error=${encodeURIComponent('State does not match.')}` }); res.end(); - throw new Error('State does not match.'); + deferred.reject(new Error('State does not match.')); + break; } if (this.nonce !== nonce) { res.writeHead(302, { location: `/?error=${encodeURIComponent('Nonce does not match.')}` }); res.end(); - throw new Error('Nonce does not match.'); + deferred.reject(new Error('Nonce does not match.')); + break; } deferred.resolve({ code, state }); res.writeHead(302, { location: '/' });