UNPKG

@xboxreplay/xboxlive-auth

Version:

A light but advanced Xbox Live authentication module with OAuth2.0 and Electron support

69 lines (68 loc) 4.09 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.xbl = exports.live = exports.authenticate = exports.authenticateWithUserRefreshToken = exports.authenticateWithUserCredentials = void 0; const live_1 = require("./core/live"); const xboxlive_1 = require("./core/xboxlive"); const postLiveAuthenticate = (liveAuthResponse_1, ...args_1) => __awaiter(void 0, [liveAuthResponse_1, ...args_1], void 0, function* (liveAuthResponse, preamble = 't', options = {}) { const userTokenResponse = yield (0, xboxlive_1.exchangeRpsTicketForUserToken)(liveAuthResponse.access_token, preamble); const XSTSResponse = yield (0, xboxlive_1.exchangeTokensForXSTSToken)({ userTokens: [userTokenResponse.Token], deviceToken: options.deviceToken, titleToken: options.titleToken }, { XSTSRelyingParty: options.XSTSRelyingParty, optionalDisplayClaims: options.optionalDisplayClaims, sandboxId: options.sandboxId }); if (options.raw !== true) { return { xuid: XSTSResponse.DisplayClaims.xui[0].xid || null, user_hash: XSTSResponse.DisplayClaims.xui[0].uhs, xsts_token: XSTSResponse.Token, display_claims: XSTSResponse.DisplayClaims.xui[0], expires_on: XSTSResponse.NotAfter }; } return { 'login.live.com': liveAuthResponse, 'user.auth.xboxlive.com': userTokenResponse, 'xsts.auth.xboxlive.com': XSTSResponse }; }); const authenticateWithUserCredentials = (email_1, password_1, ...args_1) => __awaiter(void 0, [email_1, password_1, ...args_1], void 0, function* (email, password, options = {}) { const credentials = { email, password }; const liveAuthResponse = yield (0, live_1.authenticate)(credentials); return postLiveAuthenticate(liveAuthResponse, 't', options); }); exports.authenticateWithUserCredentials = authenticateWithUserCredentials; exports.authenticateWithUserRefreshToken = (() => { let __rt; return (refreshToken_1, ...args_1) => __awaiter(void 0, [refreshToken_1, ...args_1], void 0, function* (refreshToken, refreshOptions = null, options = {}) { const liveAuthResponse = yield exports.live.refreshAccessToken(__rt || refreshToken, refreshOptions === null || refreshOptions === void 0 ? void 0 : refreshOptions.clientId, refreshOptions === null || refreshOptions === void 0 ? void 0 : refreshOptions.scope, refreshOptions === null || refreshOptions === void 0 ? void 0 : refreshOptions.clientSecret); __rt = liveAuthResponse.refresh_token || refreshToken; return postLiveAuthenticate(liveAuthResponse, refreshOptions === null || refreshOptions === void 0 ? void 0 : refreshOptions.preamble, options); }); })(); exports.authenticate = exports.authenticateWithUserCredentials; exports.live = { preAuth: live_1.preAuth, getAuthorizeUrl: live_1.getAuthorizeUrl, authenticate: live_1.authenticate, refreshAccessToken: live_1.refreshAccessToken, exchangeCodeForAccessToken: live_1.exchangeCodeForAccessToken }; exports.xbl = { EXPERIMENTAL_createDummyWin32DeviceToken: xboxlive_1.EXPERIMENTAL_createDummyWin32DeviceToken, exchangeRpsTicketForUserToken: xboxlive_1.exchangeRpsTicketForUserToken, exchangeTokensForXSTSToken: xboxlive_1.exchangeTokensForXSTSToken, exchangeTokenForXSTSToken: xboxlive_1.exchangeTokenForXSTSToken };