diff --git a/app/assets/js/authmanager.js b/app/assets/js/authmanager.js index eebfeda..3afdf1d 100644 --- a/app/assets/js/authmanager.js +++ b/app/assets/js/authmanager.js @@ -401,8 +401,8 @@ async function validateSelectedMojangAccount(){ return true } } - } + /** * Validate the selected account with Skirda's authserver. If the account is not valid, * we will attempt to refresh the access token and update that value. If that fails, a @@ -411,19 +411,9 @@ async function validateSelectedMojangAccount(){ * @returns {Promise.} Promise which resolves to true if the access token is valid, * otherwise false. */ -const auth_api_url = 'https://skirda.brzezinski.ru' async function validateSelectedSkirdaAccount(){ const current = ConfigManager.getSelectedAccount() - console.log(current) - const resp = await fetch(`${auth_api_url}/auth/refresh`, { - headers: { - 'Content-Type': 'application/json', - 'Authorization': current.accessToken, - } - }) - - console.log(resp) - return resp.status === 200 + return await SkirdaAuth.YggRefresh(current.accessToken) } /** diff --git a/app/assets/js/distromanager.js b/app/assets/js/distromanager.js index 5efcf6e..410124f 100644 --- a/app/assets/js/distromanager.js +++ b/app/assets/js/distromanager.js @@ -3,7 +3,7 @@ const ConfigManager = require('./configmanager') // Old WesterosCraft url. // exports.REMOTE_DISTRO_URL = 'http://mc.westeroscraft.com/WesterosCraftLauncher/distribution.json' -exports.REMOTE_DISTRO_URL = 'http://localhost:8090/distribution.json' +// exports.REMOTE_DISTRO_URL = 'http://localhost:8090/distribution.json' // exports.REMOTE_DISTRO_URL = 'https://helios-files.geekcorner.eu.org/distribution.json' // exports.REMOTE_DISTRO_URL = 'https://skirda-minecraft-distribution.brzezinski.ru/distribution.json' // exports.REMOTE_DISTRO_URL = 'https://helios-files.geekcorner.eu.org/distribution.json' @@ -12,6 +12,7 @@ exports.REMOTE_DISTRO_URL = 'http://localhost:8090/distribution.json' // exports.REMOTE_DISTRO_URL = 'http://skirda-nebula.brzezinski.ru/distribution.json' // exports.REMOTE_DISTRO_URL = 'http://gregbrzezinski:8080/distribution/manifest' // exports.REMOTE_DISTRO_URL = 'http://localhost:8080/distribution/files/files/distribution.json' +exports.REMOTE_DISTRO_URL = 'https://cdn.brzezinski.ru/nebula/distribution.json' const api = new DistributionAPI( ConfigManager.getLauncherDirectory(), diff --git a/app/assets/js/processbuilder.js b/app/assets/js/processbuilder.js index 42b976a..bf70e94 100644 --- a/app/assets/js/processbuilder.js +++ b/app/assets/js/processbuilder.js @@ -362,6 +362,7 @@ class ProcessBuilder { let args = [] + // Classpath Argument args.push('-cp') args.push(this.classpathArg(mods, tempNativePath).join(ProcessBuilder.getClasspathSeparator())) @@ -375,10 +376,11 @@ class ProcessBuilder { args.push('-Xms' + ConfigManager.getMinRAM(this.server.rawServer.id)) args = args.concat(ConfigManager.getJVMOptions(this.server.rawServer.id)) args.push('-Djava.library.path=' + tempNativePath) - args.push('-Dminecraft.api.auth.host=https://skirda.brzezinski.ru/yggdrasil/auth') - args.push('-Dminecraft.api.account.host=https://skirda.brzezinski.ru/yggdrasil/account') - args.push('-Dminecraft.api.session.host=https://skirda.brzezinski.ru/yggdrasil') - args.push('-Dminecraft.api.services.host=https://skirda.brzezinski.ru/yggdrasil/services)') + + args.push('-Dminecraft.api.auth.host=https://yggdrasil.brzezinski.ru/auth') + args.push('-Dminecraft.api.account.host=https://yggdrasil.brzezinski.ru/account') + args.push('-Dminecraft.api.session.host=https://yggdrasil.brzezinski.ru') + args.push('-Dminecraft.api.services.host=https://yggdrasil.brzezinski.ru/services') // Main Java Class args.push(this.modManifest.mainClass) @@ -409,6 +411,12 @@ class ProcessBuilder { // Debug securejarhandler // args.push('-Dbsl.debug=true') + args.push('-Dminecraft.api.auth.host=https://yggdrasil.brzezinski.ru/auth') + args.push('-Dminecraft.api.account.host=https://yggdrasil.brzezinski.ru/account') + args.push('-Dminecraft.api.session.host=https://yggdrasil.brzezinski.ru') + args.push('-Dminecraft.api.services.host=https://yggdrasil.brzezinski.ru/services') + + if(this.modManifest.arguments.jvm != null) { for(const argStr of this.modManifest.arguments.jvm) { args.push(argStr diff --git a/app/assets/js/scripts/loginOptions.js b/app/assets/js/scripts/loginOptions.js index 42f5ec4..ae07175 100644 --- a/app/assets/js/scripts/loginOptions.js +++ b/app/assets/js/scripts/loginOptions.js @@ -104,10 +104,12 @@ loginOptionSkirdaAuth.onclick = (e) => { SkirdaAuth.Init().then((result) => { if (result.error) { console.error(result) + switchView(getCurrentView(), VIEWS.loginOptions, 500, 500, async () => {}) } else { SkirdaAuth.YggdrasilAuth(result.token).then(ygg_res => { if (ygg_res.error !== undefined) { console.error(ygg_res) + switchView(getCurrentView(), VIEWS.loginOptions, 500, 500, async () => {}) } else { AuthManager.addSkirdaAccount( ygg_res.profile.id, diff --git a/app/assets/js/scripts/loginSkirda.js b/app/assets/js/scripts/loginSkirda.js index 15f5404..5df78f9 100644 --- a/app/assets/js/scripts/loginSkirda.js +++ b/app/assets/js/scripts/loginSkirda.js @@ -1,5 +1,3 @@ -const sk_tg_auth_api_url = 'https://skirda.brzezinski.ru/auth' - /** @typedef {Object} SkirdaAuthError * @property {string} error */ @@ -33,6 +31,10 @@ const sk_tg_auth_api_url = 'https://skirda.brzezinski.ru/auth' class SkirdaAuth { + static #ygg_auth_api_url = 'https://skirda.brzezinski.ru/yggdrasil' + static #sk_tg_auth_api_url = 'https://skirda.brzezinski.ru/auth' + + constructor() { console.log('Skirda Auth') } @@ -41,16 +43,20 @@ class SkirdaAuth { * @returns {Promise} */ static async #fetchInit() { - const resp = await fetch(`${sk_tg_auth_api_url}/telegram/init`, {}) + const resp = await fetch(`${SkirdaAuth.#sk_tg_auth_api_url}/telegram/init`, {}) if (!resp.ok) { - throw new Error(`Response status: ${resp.status}`) + return { + error: 'unknown error on auth request' + } } try { return await resp.json() } catch (error) { console.error(error.message) - return null + return { + error: error.message, + } } } @@ -61,6 +67,10 @@ class SkirdaAuth { static async Init() { const initResp = await SkirdaAuth.#fetchInit() + if (initResp.error !== undefined) { + return initResp + } + await shell.openExternal(initResp.redirect_url) // const yggResp = await SkirdaAuth.#yggdrasilAuth(authResult.token) @@ -78,7 +88,9 @@ class SkirdaAuth { const resp = await fetch(subscribe_url, {}) try { if (!resp.ok) { - throw new Error(`Response status: ${resp.status}`) + return { + error: 'unknown error on subscribe to auth result', + } } return await resp.json() } catch (error) { @@ -89,16 +101,15 @@ class SkirdaAuth { } /** - * @param {string} token + * @param {string} skirdaToken * @return {Promise} * */ - static async YggdrasilAuth(token) { - const ygg_auth_api_url = 'https://skirda.brzezinski.ru' - const resp = await fetch(`${ygg_auth_api_url}/yggdrasil/skirda/authenticate`, { + static async YggdrasilAuth(skirdaToken) { + const resp = await fetch(`${SkirdaAuth.#ygg_auth_api_url}/skirda/authenticate`, { headers: { 'Content-Type': 'application/json', - 'Authorization': token - } + 'Authorization': skirdaToken + }, }) try { @@ -117,8 +128,7 @@ class SkirdaAuth { * @return {Promise} * */ static async CheckFreeUsername(token, username) { - const ygg_auth_api_url = 'https://skirda.brzezinski.ru' - const resp = await fetch(`${ygg_auth_api_url}/yggdrasil/skirda/checkFreeUsername`, { + const resp = await fetch(`${SkirdaAuth.#ygg_auth_api_url}/skirda/checkFreeUsername`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -136,4 +146,27 @@ class SkirdaAuth { } } + + /** + * @param {string} yggToken + * @param {string} skirdaToken + * @return {Promise} + * */ + static async YggRefresh(yggToken, skirdaToken) { + const resp = await fetch(`${SkirdaAuth.#ygg_auth_api_url}/refresh`, { + method: 'POST', + body: JSON.stringify({ + 'accessToken': yggToken, + 'clientToken': skirdaToken, // This is skirda token + }) + }) + + try { + const respJSON = await resp.json() + return respJSON.error === undefined + } catch (error) { + return false + } + + } } \ No newline at end of file