Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions #7

Open
xhendrikg opened this issue Sep 4, 2021 · 1 comment
Open

Questions #7

xhendrikg opened this issue Sep 4, 2021 · 1 comment

Comments

@xhendrikg
Copy link

Hello, i have some questions. How can i use env "variables" inside fetches? (marked with 1)
And how is the authorization variable working? I think in the fetch the two """ are missing. I dont think fetch work without it but i dont know.

My code:
`const fs = require('fs');
const fetch = require('node-fetch');
require('dotenv').config();

var authorization = "Bearer ";
console.log(process.env)
console.log(Logging in as ${process.env.MSP_USERNAME}...\n);

console.log(process.env);

//get refresh token
fetch("https://eu.mspapis.com/loginidentity/connect/token", {
"headers": {
"accept": "/",
"accept-language": "en-GB,en;q=0.9,en-US;q=0.8,sv;q=0.7",
"content-type": "application/x-www-form-urlencoded",
"sec-ch-ua": ""Chromium";v="92", " Not A;Brand";v="99", "Microsoft Edge";v="92"",
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site"
},
"referrer": "https://moviestarplanet2.de/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": client_id=unity.client&client_secret=secret&grant_type=password&scope=openid%20nebula%20offline_access&username=DE%7c${process.env.MSP_USERNAME}&password=${process.env.MSP_PASSWORD}&acr_values=gameId%3aj68d,
"method": "POST",
"mode": "cors"
}).then(res => res.json())
.then(loginidentity => {
if (loginidentity.error) return console.error(Error found, loginidentity);
console.log(Success! Logged in as ${process.env.MSP_USERNAME}.\n)

    //get final bearer token
    fetch("https://eu.mspapis.com/loginidentity/connect/token", {
            "headers": {
                "accept": "*/*",
                "accept-language": "en-GB,en;q=0.9",
                "authorization": "Basic dW5pdHkuY2xpZW50OnNlY3JldA==",
                "content-type": "application/x-www-form-urlencoded",
                "sec-ch-ua": "\"Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Microsoft Edge\";v=\"92\"",
                "sec-ch-ua-mobile": "?0",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "cross-site"
            },
            "referrer": "https://moviestarplanet2.de/",  
            "referrerPolicy": "strict-origin-when-cross-origin",
            "body": `grant_type=refresh_token&refresh_token=${loginidentity.refresh_token}&acr_values=gameId%3aj68d%20profileId%3a${process.env.MSP_ID}`,
            "method": "POST",
            "mode": "cors"
        }).then(res => res.json())
        .then(fullidentity => {
            authorization += fullidentity.access_token;

            console.log(`Authorized as ${process.env.MSP_USERNAME}\n`);

//start of own code

//111111111111111111111111111111111111111111111111111111111111111111111111
//hier muss userId geändert werden
fetch("https://eu.mspapis.com/timelimitedrewards/v1/profiles/${process.env.MSP_ID}/games/j68d/rewards/daily_pickup", {
"headers": {
"accept": "/",
"accept-language": "de-DE,de;q=0.9",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site"
},
"referrer": "https://moviestarplanet2.de/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": null,
"method": "OPTIONS",
"mode": "cors"
});

//222222222222222222222222222222222222222222
//hier muss userId geändert werden
//hier muss bearer verändert werden (vvlt schon gefixt mit variable "authorization") -----glaube nein
fetch("https://eu.mspapis.com/timelimitedrewards/v1/profiles/${process.env.MSP_ID}/games/j68d/rewards/daily_pickup", {
"headers": {
"accept": "/",
"accept-language": "de-DE,de;q=0.9",
"authorization": authorization,
"content-type": "application/json",
"sec-ch-ua": ""Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"",
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site"
},
"referrer": "https://moviestarplanet2.de/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "{"state":"Claimed"}",
"method": "PUT",
"mode": "cors"
});});});

`

@salmonslay
Copy link
Owner

You can use template literals to use variables in a string.

And how is the authorization variable working? I think in the fetch the two """ are missing.

If you're referring to L85, it's written correctly. It's just setting the value of headers.authorization to the variable authorization.
https://github.com/LiterallyFabian/MSPet.js/blob/a0c542dfc02d95ccd096e2b23adf4eaa37c81901/index.js#L84-L86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants