@fnlb-project/fnbr
Version:
A library to interact with Epic Games' Fortnite HTTP and XMPP services
108 lines • 4.85 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const url_1 = require("url");
const AuthSession_1 = tslib_1.__importDefault(require("./AuthSession"));
const enums_1 = require("../../resources/enums");
const Endpoints_1 = tslib_1.__importDefault(require("../../resources/Endpoints"));
class EOSDeploymentAuthSession extends AuthSession_1.default {
constructor(client, data, clientSecret) {
super(client, {
access_token: data.access_token,
expires_at: data.expires_at,
expires_in: data.expires_in,
token_type: data.token_type,
account_id: data.product_user_id,
client_id: data.deployment_id,
}, clientSecret, enums_1.AuthSessionType.EOSDeployment);
this.nonce = data.nonce;
this.features = data.features;
this.organizationId = data.organization_id;
this.productId = data.product_id;
this.sandboxId = data.sandbox_id;
this.deploymentId = data.deployment_id;
this.organizationUserId = data.organization_user_id;
this.productUserId = data.product_user_id;
this.productUserIdCreated = data.product_user_id_created;
this.idToken = data.id_token;
}
async verify() {
return !this.isExpired;
}
async revoke() {
clearTimeout(this.refreshTimeout);
this.refreshTimeout = undefined;
}
async refresh() {
if (this.refreshLock.isLocked) {
await this.refreshLock.wait();
return;
}
this.refreshLock.lock();
try {
clearTimeout(this.refreshTimeout);
this.refreshTimeout = undefined;
const session = await this.client.auth.fortniteEOSDeploymentAuthenticate();
this.accessToken = session.accessToken;
this.expiresAt = session.expiresAt;
this.nonce = session.nonce;
this.features = session.features;
this.organizationId = session.organizationId;
this.productId = session.productId;
this.sandboxId = session.sandboxId;
this.deploymentId = session.deploymentId;
this.organizationUserId = session.organizationUserId;
this.productUserId = session.productUserId;
this.productUserIdCreated = session.productUserIdCreated;
this.idToken = session.idToken;
this.initRefreshTimeout();
}
finally {
this.refreshLock.unlock();
}
}
initRefreshTimeout() {
clearTimeout(this.refreshTimeout);
this.refreshTimeout = setTimeout(() => this.refresh(), this.expiresAt.getTime() - Date.now() - 5 * 60 * 1000);
}
static async create(client, clientId, clientSecret, externalAuthToken, deploymentId) {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
'Accept-Encoding': 'identity',
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`,
'X-Epic-Correlation-ID': `EOS-${Math.random().toString(36).substring(2, 15)}`,
'User-Agent': 'EOS-SDK/1.19.4020.0-52482444 (Windows/10.0.26100.8115.64bit) Fortnite/++Fortnite+Release-40.20-CL-52900211',
'X-EOS-Version': '1.19.4020.0-52482444',
};
let authRes = await client.http.request({
method: 'POST',
url: Endpoints_1.default.EOS_DEPLOYMENT_TOKEN,
headers,
data: new url_1.URLSearchParams({
grant_type: 'external_auth',
external_auth_type: 'epicgames_access_token',
external_auth_token: externalAuthToken,
deployment_id: deploymentId,
nonce: Math.random().toString(36).substring(2, 15),
}).toString(),
}).catch((err) => (err && 'errorData' in err) ? err.errorData : err);
if (authRes && 'errorCode' in authRes) {
if (authRes.continuation_token) {
authRes = await client.http.request({
method: 'POST',
url: Endpoints_1.default.EOS_USERS,
headers: { ...headers, Authorization: `Bearer ${authRes.continuation_token}` },
});
}
else {
throw new Error(`[AUTH] EOS Deployment token request failed: ${authRes.errorMessage} ${JSON.stringify(authRes !== null && authRes !== void 0 ? authRes : {})}`);
}
}
const session = new EOSDeploymentAuthSession(client, authRes, clientSecret);
session.initRefreshTimeout();
return session;
}
}
exports.default = EOSDeploymentAuthSession;
//# sourceMappingURL=EOSDeploymentAuthSession.js.map