mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 12:16:21 +03:00
Merge pull request #22 from Coding-Kiwi/master
Updated error handling in authenticator
This commit is contained in:
commit
69a754721f
1 changed files with 29 additions and 26 deletions
|
@ -3,8 +3,8 @@ const uuid = require('uuid/v1');
|
||||||
const api_url = "https://authserver.mojang.com";
|
const api_url = "https://authserver.mojang.com";
|
||||||
|
|
||||||
module.exports.getAuth = function (username, password) {
|
module.exports.getAuth = function (username, password) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
if(!password) {
|
if (!password) {
|
||||||
const user = {
|
const user = {
|
||||||
access_token: uuid(),
|
access_token: uuid(),
|
||||||
client_token: uuid(),
|
client_token: uuid(),
|
||||||
|
@ -31,10 +31,10 @@ module.exports.getAuth = function (username, password) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, function(error, response, body) {
|
request.post(requestObject, function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
if(!body.selectedProfile) {
|
if (!body || !body.selectedProfile) {
|
||||||
throw new Error("Validation error: " + response.statusMessage);
|
return reject("Validation error: " + response.statusMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const userProfile = {
|
const userProfile = {
|
||||||
|
@ -52,7 +52,7 @@ module.exports.getAuth = function (username, password) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.validate = function (access_token, client_token) {
|
module.exports.validate = function (access_token, client_token) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
url: api_url + "/validate",
|
url: api_url + "/validate",
|
||||||
json: {
|
json: {
|
||||||
|
@ -61,16 +61,17 @@ module.exports.validate = function (access_token, client_token) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, async function(error, response, body) {
|
request.post(requestObject, async function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
|
|
||||||
if(!body) resolve(true); else resolve(false);
|
if (!body) resolve(true);
|
||||||
|
else reject(body);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.refreshAuth = function (accessToken, clientToken, selectedProfile) {
|
module.exports.refreshAuth = function (accessToken, clientToken, selectedProfile) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
url: api_url + "/refresh",
|
url: api_url + "/refresh",
|
||||||
json: {
|
json: {
|
||||||
|
@ -81,10 +82,10 @@ module.exports.refreshAuth = function (accessToken, clientToken, selectedProfile
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, function(error, response, body) {
|
request.post(requestObject, function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
if(!body.selectedProfile) {
|
if (!body || !body.selectedProfile) {
|
||||||
throw new Error("Validation error: " + response.statusMessage);
|
return reject("Validation error: " + response.statusMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const userProfile = {
|
const userProfile = {
|
||||||
|
@ -100,8 +101,8 @@ module.exports.refreshAuth = function (accessToken, clientToken, selectedProfile
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.invalidate = function(accessToken, clientToken) {
|
module.exports.invalidate = function (accessToken, clientToken) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
url: api_url + "/invalidate",
|
url: api_url + "/invalidate",
|
||||||
json: {
|
json: {
|
||||||
|
@ -110,16 +111,17 @@ module.exports.invalidate = function(accessToken, clientToken) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, function(error, response, body) {
|
request.post(requestObject, function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
|
|
||||||
if(!body) resolve(true); else resolve(false);
|
if (!body) resolve(true);
|
||||||
|
else reject(body);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.signOut = function(username, password) {
|
module.exports.signOut = function (username, password) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
url: api_url + "/signout",
|
url: api_url + "/signout",
|
||||||
json: {
|
json: {
|
||||||
|
@ -128,10 +130,11 @@ module.exports.signOut = function(username, password) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, function(error, response, body) {
|
request.post(requestObject, function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
|
|
||||||
if(!body) resolve(true); else resolve(false);
|
if (!body) resolve(true);
|
||||||
|
else reject(body);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue