From aee045a1a426c538e4b6f0a67038314662107992 Mon Sep 17 00:00:00 2001 From: Nightmaregodss <81895400+Nightmaregodss@users.noreply.github.com> Date: Sun, 3 Jul 2022 10:00:41 +0530 Subject: [PATCH] Update authmanager.js removed Mojang login since it works no longer --- app/assets/js/authmanager.js | 98 ------------------------------------ 1 file changed, 98 deletions(-) diff --git a/app/assets/js/authmanager.js b/app/assets/js/authmanager.js index 3f431440..bb59dfd2 100644 --- a/app/assets/js/authmanager.js +++ b/app/assets/js/authmanager.js @@ -12,7 +12,6 @@ const ConfigManager = require('./configmanager') const { LoggerUtil } = require('helios-core') const { RestResponseStatus } = require('helios-core/common') -const { MojangRestAPI, mojangErrorDisplayable, MojangErrorCode } = require('helios-core/mojang') const { MicrosoftAuth, microsoftErrorDisplayable, MicrosoftErrorCode } = require('helios-core/microsoft') const { AZURE_CLIENT_ID } = require('./ipcconstants') @@ -20,43 +19,6 @@ const log = LoggerUtil.getLogger('AuthManager') // Functions -/** - * Add a Mojang account. This will authenticate the given credentials with Mojang's - * authserver. The resultant data will be stored as an auth account in the - * configuration database. - * - * @param {string} username The account username (email if migrated). - * @param {string} password The account password. - * @returns {Promise.} Promise which resolves the resolved authenticated account object. - */ -exports.addMojangAccount = async function(username, password) { - try { - const response = await MojangRestAPI.authenticate(username, password, ConfigManager.getClientToken()) - console.log(response) - if(response.responseStatus === RestResponseStatus.SUCCESS) { - - const session = response.data - if(session.selectedProfile != null){ - const ret = ConfigManager.addMojangAuthAccount(session.selectedProfile.id, session.accessToken, username, session.selectedProfile.name) - if(ConfigManager.getClientToken() == null){ - ConfigManager.setClientToken(session.clientToken) - } - ConfigManager.save() - return ret - } else { - return Promise.reject(mojangErrorDisplayable(MojangErrorCode.ERROR_NOT_PAID)) - } - - } else { - return Promise.reject(mojangErrorDisplayable(response.mojangErrorCode)) - } - - } catch (err){ - log.error(err) - return Promise.reject(mojangErrorDisplayable(MojangErrorCode.UNKNOWN)) - } -} - const AUTH_MODE = { FULL: 0, MS_REFRESH: 1, MC_REFRESH: 2 } /** @@ -156,31 +118,6 @@ exports.addMicrosoftAccount = async function(authCode) { return ret } -/** - * Remove a Mojang account. This will invalidate the access token associated - * with the account and then remove it from the database. - * - * @param {string} uuid The UUID of the account to be removed. - * @returns {Promise.} Promise which resolves to void when the action is complete. - */ -exports.removeMojangAccount = async function(uuid){ - try { - const authAcc = ConfigManager.getAuthAccount(uuid) - const response = await MojangRestAPI.invalidate(authAcc.accessToken, ConfigManager.getClientToken()) - if(response.responseStatus === RestResponseStatus.SUCCESS) { - ConfigManager.removeAuthAccount(uuid) - ConfigManager.save() - return Promise.resolve() - } else { - log.error('Error while removing account', response.error) - return Promise.reject(response.error) - } - } catch (err){ - log.error('Error while removing account', err) - return Promise.reject(err) - } -} - /** * Remove a Microsoft account. It is expected that the caller will invoke the OAuth logout * through the ipc renderer. @@ -199,41 +136,6 @@ exports.removeMicrosoftAccount = async function(uuid){ } } -/** - * Validate the selected account with Mojang's authserver. If the account is not valid, - * we will attempt to refresh the access token and update that value. If that fails, a - * new login will be required. - * - * @returns {Promise.} Promise which resolves to true if the access token is valid, - * otherwise false. - */ -async function validateSelectedMojangAccount(){ - const current = ConfigManager.getSelectedAccount() - const response = await MojangRestAPI.validate(current.accessToken, ConfigManager.getClientToken()) - - if(response.responseStatus === RestResponseStatus.SUCCESS) { - const isValid = response.data - if(!isValid){ - const refreshResponse = await MojangRestAPI.refresh(current.accessToken, ConfigManager.getClientToken()) - if(refreshResponse.responseStatus === RestResponseStatus.SUCCESS) { - const session = refreshResponse.data - ConfigManager.updateMojangAuthAccount(current.uuid, session.accessToken) - ConfigManager.save() - } else { - log.error('Error while validating selected profile:', refreshResponse.error) - log.info('Account access token is invalid.') - return false - } - log.info('Account access token validated.') - return true - } else { - log.info('Account access token validated.') - return true - } - } - -} - /** * Validate the selected account with Microsoft's authserver. If the account is not valid, * we will attempt to refresh the access token and update that value. If that fails, a