Fixed 'Failed to verify username.'
Send first request without clientToken, store the returned clientToken, use that for subsequent requests. Dont generate random UUID for clientToken, it can sometimes be 'bad'. Removed dependency 'uuid'. Updated 'electron-builder'.
This commit is contained in:
@@ -30,6 +30,9 @@ 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)
|
||||
if(ConfigManager.getClientToken() == null){
|
||||
ConfigManager.setClientToken(session.clientToken)
|
||||
}
|
||||
ConfigManager.save()
|
||||
return ret
|
||||
} catch (err){
|
||||
|
||||
@@ -2,7 +2,6 @@ const fs = require('fs')
|
||||
const mkpath = require('mkdirp')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const uuidV4 = require('uuid/v4')
|
||||
|
||||
const logger = require('./loggerutil')('%c[ConfigManager]', 'color: #a02d2a; font-weight: bold')
|
||||
|
||||
@@ -68,7 +67,7 @@ const DEFAULT_CONFIG = {
|
||||
},
|
||||
commonDirectory: path.join(dataPath, 'common'),
|
||||
instanceDirectory: path.join(dataPath, 'instances'),
|
||||
clientToken: uuidV4(),
|
||||
clientToken: null,
|
||||
selectedServer: null, // Resolved
|
||||
selectedAccount: null,
|
||||
authenticationDatabase: {},
|
||||
|
||||
@@ -133,16 +133,21 @@ exports.status = function(){
|
||||
*/
|
||||
exports.authenticate = function(username, password, clientToken, requestUser = true, agent = minecraftAgent){
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const body = {
|
||||
agent,
|
||||
username,
|
||||
password,
|
||||
requestUser
|
||||
}
|
||||
if(clientToken != null){
|
||||
body.clientToken = clientToken
|
||||
}
|
||||
|
||||
request.post(authpath + '/authenticate',
|
||||
{
|
||||
json: true,
|
||||
body: {
|
||||
agent,
|
||||
username,
|
||||
password,
|
||||
clientToken,
|
||||
requestUser
|
||||
}
|
||||
body
|
||||
},
|
||||
function(error, response, body){
|
||||
if(error){
|
||||
|
||||
Reference in New Issue
Block a user