From f7a3d2705ce6e08bd4b8d8ce9388d4df6030b7b4 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 1 Mar 2021 03:54:39 -0800 Subject: [PATCH] Preserve url params in redirect uri (#8495) --- src/entrypoints/core.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/entrypoints/core.ts b/src/entrypoints/core.ts index 4da6a8fb89..87c6275449 100644 --- a/src/entrypoints/core.ts +++ b/src/entrypoints/core.ts @@ -48,10 +48,19 @@ const authProm = isExternal const connProm = async (auth) => { try { const conn = await createConnection({ auth }); - - // Clear url if we have been able to establish a connection + // Clear auth data from url if we have been able to establish a connection if (location.search.includes("auth_callback=1")) { - history.replaceState(null, "", location.pathname); + const searchParams = new URLSearchParams(location.search); + // https://github.com/home-assistant/home-assistant-js-websocket/blob/master/lib/auth.ts + // Remove all data from QueryCallbackData type + searchParams.delete("auth_callback"); + searchParams.delete("code"); + searchParams.delete("state"); + history.replaceState( + null, + "", + `${location.pathname}?${searchParams.toString()}` + ); } return { auth, conn };