From 5afd9815a54c0baac04b7c5c643e63e82df86b1e Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Sun, 3 Dec 2017 08:12:55 -0500 Subject: [PATCH] Switches to use internal mojang accessors and removed 'mojang' as a dependency. First attempt at authentication storage, system will be refinded as UI is implemented further. All auth interactions should be made throught authmanager.js --- app/assets/js/actionbinder.js | 20 ++++++---- app/assets/js/authmanager.js | 25 +++++++++++++ app/assets/js/configmanager.js | 65 ++++++++++++++++++++++++++++++++- app/assets/js/processbuilder.js | 4 +- package-lock.json | 4 -- package.json | 1 - 6 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 app/assets/js/authmanager.js diff --git a/app/assets/js/actionbinder.js b/app/assets/js/actionbinder.js index 50a1fca1..ea6762bb 100644 --- a/app/assets/js/actionbinder.js +++ b/app/assets/js/actionbinder.js @@ -1,10 +1,10 @@ -const mojang = require('mojang') const path = require('path') const {AssetGuard} = require(path.join(__dirname, 'assets', 'js', 'assetguard.js')) const ProcessBuilder = require(path.join(__dirname, 'assets', 'js', 'processbuilder.js')) const ConfigManager = require(path.join(__dirname, 'assets', 'js', 'configmanager.js')) const DiscordWrapper = require(path.join(__dirname, 'assets', 'js', 'discordwrapper.js')) -const mojang2 = require(path.join(__dirname, 'assets', 'js', 'mojang.js')) +const Mojang = require(path.join(__dirname, 'assets', 'js', 'mojang.js')) +const AuthManager = require(path.join(__dirname, 'assets', 'js', 'authmanager.js')) let mojangStatusListener @@ -28,7 +28,7 @@ document.addEventListener('readystatechange', function(){ console.log('Refreshing Mojang Statuses..') try { let status = 'grey' - const statuses = await mojang2.status() + const statuses = await Mojang.status() greenCount = 0 for(let i=0; i} - an array of each stored authenticated account. + */ +exports.getAuthAccounts = function(){ + return config.authenticationDatabase +} + +/** + * Returns the authenticated account with the given uuid. Value may + * be null. + * + * @param {String} uuid - the uuid of the authenticated account. + * @returns {Object} - the authenticated account with the given uuid. + */ +exports.getAuthAccount = function(uuid){ + return config.authenticationDatabase[uuid] +} + +/** + * Update the access token of an authenticated account. + * + * @param {String} uuid - uuid of the authenticated account. + * @param {String} accessToken - the new Access Token. + * + * @returns {Object} - the authenticated account object created by this action. + */ +exports.updateAuthAccount = function(uuid, accessToken){ + config.authenticationDatabase[uuid].accessToken = accessToken + return config.authenticationDatabase[uuid] +} + +/** + * Adds an authenticated account to the database to be stored. + * + * @param {String} uuid - uuid of the authenticated account. + * @param {String} accessToken - accessToken of the authenticated account. + * @param {String} username - username (usually email) of the authenticated account. + * @param {String} displayName - in game name of the authenticated account. + * + * @returns {Object} - the authenticated account object created by this action. + */ +exports.addAuthAccount = function(uuid, accessToken, username, displayName){ + config.selectedAccount = uuid + config.authenticationDatabase[uuid] = { + accessToken, + username, + uuid, + displayName + } + return config.authenticationDatabase[uuid] +} + +/** + * Get the currently selected authenticated account. + * + * @returns {Object} - the selected authenticated account. + */ +exports.getSelectedAccount = function(){ + return config.authenticationDatabase[config.selectedAccount] +} // User Configurable Settings diff --git a/app/assets/js/processbuilder.js b/app/assets/js/processbuilder.js index 9f1da79b..e3dbf8e4 100644 --- a/app/assets/js/processbuilder.js +++ b/app/assets/js/processbuilder.js @@ -131,7 +131,7 @@ class ProcessBuilder { let val = null; switch(identifier){ case 'auth_player_name': - val = this.authUser.selectedProfile.name + val = this.authUser.displayName break case 'version_name': //val = versionData.id @@ -147,7 +147,7 @@ class ProcessBuilder { val = this.versionData.assets break case 'auth_uuid': - val = this.authUser.selectedProfile.id + val = this.authUser.uuid break case 'auth_access_token': val = this.authUser.accessToken diff --git a/package-lock.json b/package-lock.json index 0d58ed4f..c1b8d98d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1237,10 +1237,6 @@ } } }, - "mojang": { - "version": "https://registry.npmjs.org/mojang/-/mojang-0.4.1.tgz", - "integrity": "sha1-aWPEL8RlDrwASCSGvdqpB2Mhmi4=" - }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", diff --git a/package.json b/package.json index b8b5edaf..d4f53c01 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "ejs-electron": "^2.0.1", "find-java-home": "^0.2.0", "jquery": "^3.2.1", - "mojang": "^0.4.1", "request-promise-native": "^1.0.5", "uuid": "^3.1.0" },