Added function to remove an authenticated account to authmanager.js.
This commit is contained in:
parent
631c3cd6d4
commit
5475ac0c69
@ -1,6 +1,28 @@
|
||||
/**
|
||||
* AuthManager
|
||||
*
|
||||
* This module aims to abstract login procedures. Results from Mojang's REST api
|
||||
* are retrieved through our Mojang module. These results are processed and stored,
|
||||
* if applicable, in the config using the ConfigManager. All login procedures should
|
||||
* be made through this module.
|
||||
*
|
||||
* @module authmanager
|
||||
*/
|
||||
// Requirements
|
||||
const ConfigManager = require('./configmanager.js')
|
||||
const Mojang = require('./mojang.js')
|
||||
|
||||
// Functions
|
||||
|
||||
/**
|
||||
* Add an 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.<Object>} Promise which resolves to the Mojang authentication response.
|
||||
*/
|
||||
exports.addAccount = async function(username, password){
|
||||
try{
|
||||
const session = await Mojang.authenticate(username, password, ConfigManager.getClientToken)
|
||||
@ -12,6 +34,35 @@ exports.addAccount = async function(username, password){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an 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.<void>} Promise which resolves to void when the action is complete.
|
||||
*/
|
||||
exports.removeAccount = async function(uuid){
|
||||
try {
|
||||
const authAcc = ConfigManager.getAuthAccount(uuid)
|
||||
await Mojang.invalidate(authAcc.accessToken, ConfigManager.getClientToken())
|
||||
ConfigManager.removeAuthAccount(uuid)
|
||||
ConfigManager.save()
|
||||
return Promise.resolve()
|
||||
} catch (err){
|
||||
return Promise.reject(err)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* **Function is WIP**
|
||||
*
|
||||
* @returns {Promise.<boolean>} Promise which resolves to true if the access token is valid,
|
||||
* otherwise false.
|
||||
*/
|
||||
exports.validateSelected = async function(){
|
||||
const current = ConfigManager.getSelectedAccount()
|
||||
const isValid = await Mojang.validate(current.accessToken, ConfigManager.getClientToken())
|
||||
|
@ -1,5 +1,14 @@
|
||||
/**
|
||||
* Mojang
|
||||
*
|
||||
* This module serves as a minimal wrapper for Mojang's REST api.
|
||||
*
|
||||
* @module mojang
|
||||
*/
|
||||
// Requirements
|
||||
const request = require('request')
|
||||
|
||||
// Constants
|
||||
const minecraftAgent = {
|
||||
name: 'Minecraft',
|
||||
version: 1
|
||||
@ -38,6 +47,8 @@ const statuses = [
|
||||
}
|
||||
]
|
||||
|
||||
// Functions
|
||||
|
||||
/**
|
||||
* Converts a Mojang status color to a hex value. Valid statuses
|
||||
* are 'green', 'yellow', 'red', and 'grey'. Grey is a custom status
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* The initial iteration of this file will not support optional submodules.
|
||||
* Support will be added down the line, only top-level modules will recieve optional support.
|
||||
*
|
||||
*
|
||||
* TODO why are logs not working??????
|
||||
*/
|
||||
const AdmZip = require('adm-zip')
|
||||
const {AssetGuard, Library} = require('./assetguard.js')
|
||||
|
Loading…
Reference in New Issue
Block a user