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
This commit is contained in:
parent
3c7d7d79af
commit
5afd9815a5
@ -1,10 +1,10 @@
|
|||||||
const mojang = require('mojang')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const {AssetGuard} = require(path.join(__dirname, 'assets', 'js', 'assetguard.js'))
|
const {AssetGuard} = require(path.join(__dirname, 'assets', 'js', 'assetguard.js'))
|
||||||
const ProcessBuilder = require(path.join(__dirname, 'assets', 'js', 'processbuilder.js'))
|
const ProcessBuilder = require(path.join(__dirname, 'assets', 'js', 'processbuilder.js'))
|
||||||
const ConfigManager = require(path.join(__dirname, 'assets', 'js', 'configmanager.js'))
|
const ConfigManager = require(path.join(__dirname, 'assets', 'js', 'configmanager.js'))
|
||||||
const DiscordWrapper = require(path.join(__dirname, 'assets', 'js', 'discordwrapper.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
|
let mojangStatusListener
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ document.addEventListener('readystatechange', function(){
|
|||||||
console.log('Refreshing Mojang Statuses..')
|
console.log('Refreshing Mojang Statuses..')
|
||||||
try {
|
try {
|
||||||
let status = 'grey'
|
let status = 'grey'
|
||||||
const statuses = await mojang2.status()
|
const statuses = await Mojang.status()
|
||||||
greenCount = 0
|
greenCount = 0
|
||||||
for(let i=0; i<statuses.length; i++){
|
for(let i=0; i<statuses.length; i++){
|
||||||
if(statuses[i].status === 'yellow' && status !== 'red'){
|
if(statuses[i].status === 'yellow' && status !== 'red'){
|
||||||
@ -44,7 +44,7 @@ document.addEventListener('readystatechange', function(){
|
|||||||
status = 'green'
|
status = 'green'
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('mojang_status_icon').style.color = mojang2.statusToHex(status)
|
document.getElementById('mojang_status_icon').style.color = Mojang.statusToHex(status)
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Unable to refresh Mojang service status..', err)
|
console.error('Unable to refresh Mojang service status..', err)
|
||||||
@ -62,6 +62,13 @@ document.addEventListener('readystatechange', function(){
|
|||||||
let tracker;
|
let tracker;
|
||||||
|
|
||||||
testdownloads = async function(){
|
testdownloads = async function(){
|
||||||
|
|
||||||
|
if(ConfigManager.getSelectedAccount() == null){
|
||||||
|
console.error('login first.')
|
||||||
|
//in devtools AuthManager.addAccount(username, pass)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const content = document.getElementById('launch_content')
|
const content = document.getElementById('launch_content')
|
||||||
const details = document.getElementById('launch_details')
|
const details = document.getElementById('launch_details')
|
||||||
const progress = document.getElementById('launch_progress')
|
const progress = document.getElementById('launch_progress')
|
||||||
@ -115,10 +122,7 @@ testdownloads = async function(){
|
|||||||
|
|
||||||
det_text.innerHTML = 'Preparing to launch..'
|
det_text.innerHTML = 'Preparing to launch..'
|
||||||
const forgeData = await tracker.loadForgeData(serv.id)
|
const forgeData = await tracker.loadForgeData(serv.id)
|
||||||
const authUser = await mojang.auth('EMAIL', 'PASS', ConfigManager.getClientToken(), {
|
const authUser = await AuthManager.validateSelected()
|
||||||
name: 'Minecraft',
|
|
||||||
version: 1
|
|
||||||
})
|
|
||||||
let pb = new ProcessBuilder(ConfigManager.getGameDirectory(), serv, versionData, forgeData, authUser)
|
let pb = new ProcessBuilder(ConfigManager.getGameDirectory(), serv, versionData, forgeData, authUser)
|
||||||
det_text.innerHTML = 'Launching game..'
|
det_text.innerHTML = 'Launching game..'
|
||||||
let proc;
|
let proc;
|
||||||
|
25
app/assets/js/authmanager.js
Normal file
25
app/assets/js/authmanager.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
const ConfigManager = require('./configmanager.js')
|
||||||
|
const Mojang = require('./mojang.js')
|
||||||
|
|
||||||
|
exports.addAccount = function(username, password){
|
||||||
|
return new Promise(async function(resolve, reject){
|
||||||
|
const session = await Mojang.authenticate(username, password, ConfigManager.getClientToken)
|
||||||
|
const ret = ConfigManager.addAuthAccount(session.selectedProfile.id, session.accessToken, username, session.selectedProfile.name)
|
||||||
|
ConfigManager.save()
|
||||||
|
resolve(ret)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.validateSelected = function(){
|
||||||
|
return new Promise(async function(resolve, reject){
|
||||||
|
const current = ConfigManager.getSelectedAccount()
|
||||||
|
if(!await Mojang.validate(current.accessToken, ConfigManager.getClientToken)){
|
||||||
|
const session = Mojang.refresh(current.accessToken, ConfigManager.getClientToken)
|
||||||
|
const ret = ConfigManager.updateAuthAccount(current.uuid, session.accessToken)
|
||||||
|
ConfigManager.save()
|
||||||
|
resolve(ret)
|
||||||
|
} else {
|
||||||
|
resolve(current)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
@ -42,7 +42,7 @@ const DEFAULT_CONFIG = {
|
|||||||
clientToken: uuidV4(),
|
clientToken: uuidV4(),
|
||||||
selectedServer: null, // Resolved
|
selectedServer: null, // Resolved
|
||||||
selectedAccount: null,
|
selectedAccount: null,
|
||||||
authenticationDatabase: []
|
authenticationDatabase: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = null;
|
let config = null;
|
||||||
@ -118,7 +118,68 @@ exports.setSelectedServer = function(serverID){
|
|||||||
config.selectedServer = serverID
|
config.selectedServer = serverID
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Write Authentication Database/Selected Account accessors here
|
/**
|
||||||
|
* Get an array of each account currently authenticated by the launcher.
|
||||||
|
*
|
||||||
|
* @returns {Array.<Object>} - 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
|
// User Configurable Settings
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ class ProcessBuilder {
|
|||||||
let val = null;
|
let val = null;
|
||||||
switch(identifier){
|
switch(identifier){
|
||||||
case 'auth_player_name':
|
case 'auth_player_name':
|
||||||
val = this.authUser.selectedProfile.name
|
val = this.authUser.displayName
|
||||||
break
|
break
|
||||||
case 'version_name':
|
case 'version_name':
|
||||||
//val = versionData.id
|
//val = versionData.id
|
||||||
@ -147,7 +147,7 @@ class ProcessBuilder {
|
|||||||
val = this.versionData.assets
|
val = this.versionData.assets
|
||||||
break
|
break
|
||||||
case 'auth_uuid':
|
case 'auth_uuid':
|
||||||
val = this.authUser.selectedProfile.id
|
val = this.authUser.uuid
|
||||||
break
|
break
|
||||||
case 'auth_access_token':
|
case 'auth_access_token':
|
||||||
val = this.authUser.accessToken
|
val = this.authUser.accessToken
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1237,10 +1237,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mojang": {
|
|
||||||
"version": "https://registry.npmjs.org/mojang/-/mojang-0.4.1.tgz",
|
|
||||||
"integrity": "sha1-aWPEL8RlDrwASCSGvdqpB2Mhmi4="
|
|
||||||
},
|
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
"ejs-electron": "^2.0.1",
|
"ejs-electron": "^2.0.1",
|
||||||
"find-java-home": "^0.2.0",
|
"find-java-home": "^0.2.0",
|
||||||
"jquery": "^3.2.1",
|
"jquery": "^3.2.1",
|
||||||
"mojang": "^0.4.1",
|
|
||||||
"request-promise-native": "^1.0.5",
|
"request-promise-native": "^1.0.5",
|
||||||
"uuid": "^3.1.0"
|
"uuid": "^3.1.0"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user