Created
March 24, 2020 21:52
-
-
Save MixV2/52a4d92c5c1e5a4f195f2cbbd17e0cda to your computer and use it in GitHub Desktop.
Authenticating with Epic Games
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // by joe/mix | |
| const request = require("request-promise"); | |
| module.exports = { | |
| /** | |
| * Login to an account. | |
| * @param {string} email | |
| * @param {string} password | |
| */ | |
| async authenticate(email, password) { | |
| let jar = await request.jar(); | |
| await this.sendEpicRequest("https://www.epicgames.com/id/api/reputation", jar); | |
| await this.sendEpicRequest("https://www.epicgames.com/id/api/authenticate", jar); | |
| await this.sendEpicRequest("https://www.epicgames.com/id/api/location", jar); | |
| const csrf = await this.sendEpicRequest("https://www.epicgames.com/id/api/csrf", jar); | |
| const cookies = JSON.parse(JSON.stringify(jar))._jar["cookies"]; | |
| const login = await request({ | |
| url: "https://www.epicgames.com/id/api/login", | |
| method: "POST", | |
| headers: { | |
| "x-xsrf-token": cookies.find(i => i.key === "XSRF-TOKEN").value, | |
| "Content-Type": "application/json", | |
| }, | |
| jar: jar, | |
| form: { | |
| "email": email, | |
| "password": password, | |
| "rememberMe": true | |
| } | |
| }); | |
| const exchange = await request({ | |
| url: "https://www.epicgames.com/id/api/exchange", | |
| headers: { | |
| "x-xsrf-token": cookies.find(i => i.key === "XSRF-TOKEN").value, | |
| "Content-Type": "application/json", | |
| }, | |
| jar: jar, | |
| json: true, | |
| }); | |
| const token = await request({ | |
| url: "https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/token", | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/x-www-form-urlencoded", | |
| "Authorization": "basic ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ=" // https://github.com/MixV2/EpicResearch#1231-authorization-header | |
| }, | |
| form: { | |
| grant_type: "exchange_code", | |
| exchange_code: exchange["code"], | |
| includePerms: false | |
| }, | |
| json: true | |
| }) | |
| return token; | |
| }, | |
| /** | |
| * Sends an "Epic" request, reuses cookie jar and shortens to one line. | |
| * @param {string} url | |
| */ | |
| async sendEpicRequest(url, jar) { | |
| return await request({ | |
| url, | |
| jar | |
| }) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const auth = require("./auth"); | |
| /** | |
| * An async function that authenticates and logs the account token. | |
| */ | |
| ( async () => { | |
| const login = await auth.authenticate("[email protected]", "GreatPassword"); | |
| console.log(login); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello.
I tested this code but don't work properly.
If I use my email and password in test.js the response didn't return.
As a result
console.log(login); didn't run.