mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-12-23 02:13:46 +03:00
added validate and refresh endpoints to logic
This commit is contained in:
parent
8d49706303
commit
0e09106643
2 changed files with 79 additions and 4 deletions
29
README.md
29
README.md
|
@ -5,13 +5,40 @@ A script that launches Minecraft using NodeJS.
|
|||
|
||||
#### Usage
|
||||
|
||||
##### Basic Login
|
||||
```javascript
|
||||
const launcher = require('./pathtomodule');
|
||||
|
||||
launcher.authenticator("email", "password").then(auth => {
|
||||
// Save the auth to a file so it can be used later on!
|
||||
launcher.core({
|
||||
authorization: auth,
|
||||
// All of the following is required
|
||||
// All of the following is required
|
||||
root: "directory", // C:/Users/user/AppData/Roaming/.mc
|
||||
os: "windows", // windows, osx, linux
|
||||
version: {
|
||||
number: "1.13.2", // Minecraft version you want to launch
|
||||
type: "MCC-Launcher" // Type. Can be anything
|
||||
},
|
||||
memory: {
|
||||
max: "500"
|
||||
}
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
##### Using Validate and Refresh
|
||||
|
||||
```javascript
|
||||
let auth = require("pathToUserAuthJson.json");
|
||||
|
||||
const validateCheck = await launcher.authenticator.validate(auth.access_token); // required arguments.
|
||||
if(!validateCheck) {
|
||||
auth = await launcher.authenticator.refreshAuth(auth.access_token, auth.client_token, auth.selected_profile); // required arguments.
|
||||
}
|
||||
launcher.core({
|
||||
authorization: auth,
|
||||
// All of the following is required
|
||||
root: "directory", // C:/Users/user/AppData/Roaming/.mc
|
||||
os: "windows", // windows, osx, linux
|
||||
version: {
|
||||
|
|
|
@ -41,6 +41,7 @@ function getAuth(username, password) {
|
|||
client_token: uuid(),
|
||||
uuid: body.selectedProfile.id,
|
||||
name: body.selectedProfile.name,
|
||||
selected_profile: body.selectedProfile,
|
||||
user_properties: JSON.stringify((body.user || {}).properties || {})
|
||||
};
|
||||
|
||||
|
@ -49,6 +50,53 @@ function getAuth(username, password) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = async function(username, password) {
|
||||
return await getAuth(username, password);
|
||||
};
|
||||
function validate(access_token) {
|
||||
return new Promise(resolve => {
|
||||
const requestObject = {
|
||||
url: api_url + "/validate",
|
||||
json: {
|
||||
"accessToken": access_token
|
||||
}
|
||||
};
|
||||
|
||||
request.post(requestObject, async function(error, response, body) {
|
||||
if (error) resolve(error);
|
||||
|
||||
if(!body) resolve(true); else resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function refreshAuth(accessToken, clientToken, selectedProfile) {
|
||||
return new Promise(resolve => {
|
||||
const requestObject = {
|
||||
url: api_url + "/refresh",
|
||||
json: {
|
||||
"accessToken": accessToken,
|
||||
"clientToken": clientToken,
|
||||
"selectedProfile": selectedProfile,
|
||||
"requestUser": true
|
||||
}
|
||||
};
|
||||
|
||||
request.post(requestObject, function(error, response, body) {
|
||||
if (error) resolve(error);
|
||||
console.log(body);
|
||||
if(!body.selectedProfile) {
|
||||
throw new Error("Validation error: " + response.statusMessage);
|
||||
}
|
||||
|
||||
const userProfile = {
|
||||
access_token: body.accessToken,
|
||||
client_token: uuid(),
|
||||
uuid: body.selectedProfile.id,
|
||||
name: body.selectedProfile.name,
|
||||
user_properties: JSON.stringify((body.user || {}).properties || {})
|
||||
};
|
||||
|
||||
resolve(userProfile);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {getAuth, validate, refreshAuth};
|
Loading…
Add table
Reference in a new issue