From e060607dfb3fff57d080a0a39ae7f883caf0d76b Mon Sep 17 00:00:00 2001 From: IkyMax Date: Tue, 9 Apr 2024 13:32:19 -0600 Subject: [PATCH] Rollback Microsoft OAuthV2 --- app/assets/js/scripts/login.js | 3 +- app/assets/js/scripts/settings.js | 34 ++++++------- index.js | 85 ++----------------------------- 3 files changed, 20 insertions(+), 102 deletions(-) diff --git a/app/assets/js/scripts/login.js b/app/assets/js/scripts/login.js index 97642c75..30ff8937 100644 --- a/app/assets/js/scripts/login.js +++ b/app/assets/js/scripts/login.js @@ -230,4 +230,5 @@ loginButton.addEventListener('click', () => { }) toggleOverlay(true) }) -}) + +}) \ No newline at end of file diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js index 7910c92f..caba0269 100644 --- a/app/assets/js/scripts/settings.js +++ b/app/assets/js/scripts/settings.js @@ -353,9 +353,8 @@ document.getElementById('settingsAddMojangAccount').onclick = (e) => { // Bind the add microsoft account button. document.getElementById('settingsAddMicrosoftAccount').onclick = (e) => { - document.getElementById("waitingText").innerHTML = "Please login in the window that has just opened" switchView(getCurrentView(), VIEWS.waiting, 500, 500, () => { - ipcRenderer.send(MSFT_OPCODE.OPEN_LOGIN, VIEWS.landing, VIEWS.settings) + ipcRenderer.send(MSFT_OPCODE.OPEN_LOGIN, VIEWS.settings, VIEWS.settings) }) } @@ -384,8 +383,7 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGIN, (_, ...arguments_) => { }) toggleOverlay(true) }) - } else if (arguments_[0] === MSFT_REPLY_TYPE.SUCCESS) { - document.getElementById("waitingText").innerHTML = "Retrieving your account information from Microsoft" + } else if(arguments_[0] === MSFT_REPLY_TYPE.SUCCESS) { const queryMap = arguments_[1] const viewOnClose = arguments_[2] @@ -408,7 +406,7 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGIN, (_, ...arguments_) => { setOverlayHandler(() => { toggleOverlay(false) }) - if (errorDesc !== "The user has denied access to the scope requested by the client application.") toggleOverlay(true)//If the user clicks "Back" button and closes the window + toggleOverlay(true) }) } else { @@ -417,7 +415,6 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGIN, (_, ...arguments_) => { const authCode = queryMap.code AuthManager.addMicrosoftAccount(authCode).then(value => { - document.getElementById("waitingText").innerHTML = "Finished" updateSelectedAccount(value) switchView(getCurrentView(), viewOnClose, 500, 500, async () => { await prepareSettings() @@ -499,7 +496,7 @@ function bindAuthAccountLogOut(){ } else { processLogOut(val, isLastAccount) } - + } }) } @@ -519,7 +516,6 @@ function processLogOut(val, isLastAccount){ if(targetAcc.type === 'microsoft') { msAccDomElementCache = parent switchView(getCurrentView(), VIEWS.waiting, 500, 500, () => { - document.getElementById("waitingText").innerHTML = "Removing your Microsoft account from the launcher" //We actually don't have to wait anything from Mirosoft ipcRenderer.send(MSFT_OPCODE.OPEN_LOGOUT, uuid, isLastAccount) }) } else { @@ -530,16 +526,16 @@ function processLogOut(val, isLastAccount){ updateSelectedAccount(selAcc) validateSelectedAccount() } - $(parent).fadeOut(250, () => { - parent.remove() - }) + if(isLastAccount) { + loginOptionsCancelEnabled(false) + loginOptionsViewOnLoginSuccess = VIEWS.settings + loginOptionsViewOnLoginCancel = VIEWS.loginOptions + switchView(getCurrentView(), VIEWS.loginOptions) + } + }) + $(parent).fadeOut(250, () => { + parent.remove() }) - if (isLastAccount) { - loginOptionsCancelEnabled(false) - loginOptionsViewOnLoginSuccess = VIEWS.landing - loginOptionsViewOnLoginCancel = VIEWS.loginOptions - switchView(getCurrentView(), VIEWS.loginOptions) - } } } @@ -572,7 +568,7 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGOUT, (_, ...arguments_) => { const prevSelAcc = ConfigManager.getSelectedAccount() msftLogoutLogger.info('Logout Successful. uuid:', uuid) - + AuthManager.removeMicrosoftAccount(uuid) .then(() => { if(!isLastAccount && uuid === prevSelAcc.uuid){ @@ -583,7 +579,7 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGOUT, (_, ...arguments_) => { } if(isLastAccount) { loginOptionsCancelEnabled(false) - loginOptionsViewOnLoginSuccess = VIEWS.landing + loginOptionsViewOnLoginSuccess = VIEWS.settings loginOptionsViewOnLoginCancel = VIEWS.loginOptions switchView(getCurrentView(), VIEWS.loginOptions) } diff --git a/index.js b/index.js index 8e1ef6e6..7060c3c6 100644 --- a/index.js +++ b/index.js @@ -109,7 +109,7 @@ ipcMain.handle(SHELL_OPCODE.TRASH_ITEM, async (event, ...args) => { app.disableHardwareAcceleration() - +const REDIRECT_URI_PREFIX = 'https://login.microsoftonline.com/common/oauth2/nativeclient?' // Microsoft Auth Login let msftAuthWindow @@ -227,8 +227,8 @@ let win function createWindow() { win = new BrowserWindow({ - width: 1143, - height: 700, + width: 980, + height: 552, icon: getPlatformIcon('SealCircle'), frame: false, webPreferences: { @@ -358,83 +358,4 @@ app.on('activate', () => { if (win === null) { createWindow() } -}) - -const REDIRECT_URI_PREFIX = 'https://login.microsoftonline.com/common/oauth2/nativeclient?' - -// Microsoft Auth Login -let msftAuthWindow -let msftAuthSuccess -let msftAuthViewSuccess -let msftAuthViewOnClose -ipcMain.on(MSFT_OPCODE.OPEN_LOGIN, (ipcEvent, ...arguments_) => { - /* - Clear cookies from live.com and github.com from Microsoft Login, since there isn't an actual way to invalidate Microsoft access token - */ - session.defaultSession.cookies.get({ domain: 'live.com' }).then((cookies) => { - for (let cookie of cookies) { - let urlcookie = `http${cookie.secure ? "s" : ""}://${cookie.domain.replace(/$\./, "") + cookie.path}`; - session.defaultSession.cookies.remove(urlcookie, cookie.name) - } - }) - session.defaultSession.cookies.get({ domain: 'github.com' }).then((cookies) => { - for (let cookie of cookies) { - let urlcookie = `http${cookie.secure ? "s" : ""}://${cookie.domain.replace(/$\./, "") + cookie.path}`; - session.defaultSession.cookies.remove(urlcookie, cookie.name) - } - }) - if (msftAuthWindow) { - ipcEvent.reply(MSFT_OPCODE.REPLY_LOGIN, MSFT_REPLY_TYPE.ERROR, MSFT_ERROR.ALREADY_OPEN, msftAuthViewOnClose) - return - } - msftAuthSuccess = false - msftAuthViewSuccess = arguments_[0] - msftAuthViewOnClose = arguments_[1] - msftAuthWindow = new BrowserWindow({ - parent: win, - modal: true, - resizable: false, - title: 'Microsoft Login', - backgroundColor: '#222222', - width: 520, - height: 700, - frame: true, - icon: getPlatformIcon('SealCircle') - }) - - msftAuthWindow.on('closed', () => { - msftAuthWindow = undefined - }) - - msftAuthWindow.on('close', () => { - if (!msftAuthSuccess) { - ipcEvent.reply(MSFT_OPCODE.REPLY_LOGIN, MSFT_REPLY_TYPE.ERROR, MSFT_ERROR.NOT_FINISHED, msftAuthViewOnClose) - } - }) - - msftAuthWindow.webContents.on('did-navigate', (_, uri) => { - if (uri.startsWith(REDIRECT_URI_PREFIX)) { - let queries = uri.substring(REDIRECT_URI_PREFIX.length).split('#', 1).toString().split('&') - let queryMap = {} - - queries.forEach(query => { - const [name, value] = query.split('=') - queryMap[name] = decodeURI(value) - }) - - ipcEvent.reply(MSFT_OPCODE.REPLY_LOGIN, MSFT_REPLY_TYPE.SUCCESS, queryMap, msftAuthViewSuccess) - - msftAuthSuccess = true - msftAuthWindow.close() - msftAuthWindow = null - } - }) - - msftAuthWindow.removeMenu() - msftAuthWindow.loadURL(`https://login.live.com/oauth20_authorize.srf?prompt=select_account&client_id=${AZURE_CLIENT_ID}&response_type=code&scope=XboxLive.signin%20offline_access&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient&cobrandid=8058f65d-ce06-4c30-9559-473c9275a65d`) //Cobrandid adds the Minecraft branding on the login page -}) - -// Microsoft Auth Logout -ipcMain.on(MSFT_OPCODE.OPEN_LOGOUT, (ipcEvent, uuid, isLastAccount) => { - ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.SUCCESS, uuid, isLastAccount) //Just reply to the event, since logout pop up isn't that much useful }) \ No newline at end of file