From 7b9d9793cec195c0ec0a1d1f6d0150baf4c443c0 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sat, 22 Jun 2024 11:07:00 -0400 Subject: [PATCH] refactor: use URL to build href --- src/utils/auth/utils.test.ts | 2 +- src/utils/auth/utils.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utils/auth/utils.test.ts b/src/utils/auth/utils.test.ts index 9f839959e..914e90def 100644 --- a/src/utils/auth/utils.test.ts +++ b/src/utils/auth/utils.test.ts @@ -47,7 +47,7 @@ describe('utils/auth/utils.ts', () => { expect(loadURLMock).toHaveBeenCalledTimes(1); expect(loadURLMock).toHaveBeenCalledWith( - 'https://github.com/login/oauth/authorize?client_id=FAKE_CLIENT_ID_123&scope=read:user,notifications,repo', + 'https://github.com/login/oauth/authorize?client_id=FAKE_CLIENT_ID_123&scope=read%3Auser%2Cnotifications%2Crepo', ); expect(browserWindow.destroy).toHaveBeenCalledTimes(1); diff --git a/src/utils/auth/utils.ts b/src/utils/auth/utils.ts index fec3e572d..b15b84557 100644 --- a/src/utils/auth/utils.ts +++ b/src/utils/auth/utils.ts @@ -28,13 +28,15 @@ export function authGitHub( show: true, }); - const githubUrl = `https://${authOptions.hostname}/login/oauth/authorize`; - const authUrl = `${githubUrl}?client_id=${authOptions.clientId}&scope=${Constants.AUTH_SCOPE}`; + const authUrl = new URL(`https://${authOptions.hostname}`); + authUrl.pathname = '/login/oauth/authorize'; + authUrl.searchParams.append('client_id', authOptions.clientId); + authUrl.searchParams.append('scope', Constants.AUTH_SCOPE.toString()); const session = authWindow.webContents.session; session.clearStorageData(); - authWindow.loadURL(authUrl); + authWindow.loadURL(authUrl.toString()); const handleCallback = (url: Link) => { const raw_code = /code=([^&]*)/.exec(url) || null;