mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 19:52:14 -08:00
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
const ConfigManager = require('./configmanager.js')
|
|
const Mojang = require('./mojang.js')
|
|
|
|
exports.addAccount = async function(username, password){
|
|
try{
|
|
const session = await Mojang.authenticate(username, password, ConfigManager.getClientToken)
|
|
const ret = ConfigManager.addAuthAccount(session.selectedProfile.id, session.accessToken, username, session.selectedProfile.name)
|
|
ConfigManager.save()
|
|
return ret
|
|
} catch (err){
|
|
return Promise.reject(err)
|
|
}
|
|
}
|
|
|
|
exports.validateSelected = async function(){
|
|
const current = ConfigManager.getSelectedAccount()
|
|
const isValid = await Mojang.validate(current.accessToken, ConfigManager.getClientToken())
|
|
console.log(isValid)
|
|
if(!isValid){
|
|
try {
|
|
const session = await Mojang.refresh(current.accessToken, ConfigManager.getClientToken())
|
|
console.log('ses', session)
|
|
ConfigManager.updateAuthAccount(current.uuid, session.accessToken)
|
|
ConfigManager.save()
|
|
} catch(err) {
|
|
if(err && err.message === 'ForbiddenOperationException'){
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
} else {
|
|
return true
|
|
}
|
|
} |