@xboxreplay/xboxlive-auth
Advanced tools
Comparing version 3.0.2 to 3.1.1
@@ -1,3 +0,4 @@ | ||
import { ExchangeRpsTicketResponse, AuthenticateResponse, ExchangeResponse } from '../..'; | ||
import { ExchangeRpsTicketResponse, AuthenticateResponse, ExchangeResponse, TokensExchangeProperties, TokensExchangeOptions } from '../..'; | ||
export declare const exchangeRpsTicketForUserToken: (RpsTicket: string) => Promise<ExchangeRpsTicketResponse>; | ||
export declare const exchangeUserTokenForXSTSIdentity: <T extends ExchangeResponse>(userToken: string, XSTSRelyingParty?: string, raw?: boolean) => Promise<T | AuthenticateResponse>; | ||
export declare const exchangeTokensForXSTSIdentity: <T extends ExchangeResponse>({ userToken, deviceToken, titleToken }: TokensExchangeProperties, { XSTSRelyingParty, optionalDisplayClaims, raw }?: TokensExchangeOptions) => Promise<T | AuthenticateResponse>; | ||
export declare const exchangeUserTokenForXSTSIdentity: <T extends ExchangeResponse>(userToken: string, options: TokensExchangeOptions) => Promise<AuthenticateResponse | T>; |
@@ -1,77 +0,109 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const errors_1 = __importDefault(require("@xboxreplay/errors")); | ||
const axios_1 = __importDefault(require("axios")); | ||
const config_1 = __importDefault(require("./config")); | ||
const config_2 = __importDefault(require("../../config")); | ||
exports.exchangeRpsTicketForUserToken = (RpsTicket) => axios_1.default | ||
.post(config_1.default.uris.userAuthenticate, { | ||
RelyingParty: 'http://auth.xboxlive.com', | ||
TokenType: 'JWT', | ||
Properties: { | ||
AuthMethod: 'RPS', | ||
SiteName: 'user.auth.xboxlive.com', | ||
RpsTicket | ||
} | ||
}, { | ||
headers: Object.assign(Object.assign({}, config_2.default.request.baseHeaders), { Accept: 'application/json', 'x-xbl-contract-version': 0 }) | ||
}) | ||
.then(response => { | ||
if (response.status !== 200) | ||
throw errors_1.default.internal('Could not exchange specified "RpsTicket"'); | ||
else | ||
return response.data; | ||
}) | ||
.catch(err => { | ||
if (!!err.__XboxReplay__) | ||
throw err; | ||
else | ||
throw errors_1.default.internal(err.message); | ||
}); | ||
exports.exchangeUserTokenForXSTSIdentity = (userToken, XSTSRelyingParty = config_1.default.defaultRelyingParty, raw = false) => axios_1.default | ||
.post(config_1.default.uris.XSTSAuthorize, { | ||
RelyingParty: XSTSRelyingParty, | ||
TokenType: 'JWT', | ||
Properties: { | ||
UserTokens: [userToken], | ||
SandboxId: 'RETAIL' | ||
} | ||
}, { | ||
headers: Object.assign(Object.assign({}, config_2.default.request.baseHeaders), { Accept: 'application/json', 'x-xbl-contract-version': 0 }) | ||
}) | ||
.then(response => { | ||
if (response.status !== 200) { | ||
throw errors_1.default.internal('Could not exchange specified "userToken"'); | ||
} | ||
if (raw === false) { | ||
const body = response.data; | ||
return { | ||
userXUID: body.DisplayClaims.xui[0].xid || null, | ||
userHash: body.DisplayClaims.xui[0].uhs, | ||
XSTSToken: body.Token, | ||
expiresOn: body.NotAfter | ||
}; | ||
} | ||
else | ||
return response.data; | ||
}) | ||
.catch(err => { | ||
var _a; | ||
if (!!err.__XboxReplay__) | ||
throw err; | ||
else if (((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) === 400) { | ||
const isDefaultRelyingParty = XSTSRelyingParty === config_1.default.defaultRelyingParty; | ||
const computedErrorMessage = [ | ||
'Could not exchange "userToken", please', | ||
`refer to ${config_2.default.gitHubLinks.seeUserTokenIssue}` | ||
]; | ||
if (isDefaultRelyingParty === false) | ||
computedErrorMessage.splice(1, 0, 'double check the specified "XSTSRelyingParty" or'); | ||
throw errors_1.default.internal(computedErrorMessage.join(' ')); | ||
} | ||
else | ||
throw errors_1.default.internal(err.message); | ||
}); | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const errors_1 = __importDefault(require('@xboxreplay/errors')); | ||
const axios_1 = __importDefault(require('axios')); | ||
const config_1 = __importDefault(require('./config')); | ||
const config_2 = __importDefault(require('../../config')); | ||
exports.exchangeRpsTicketForUserToken = RpsTicket => | ||
axios_1.default | ||
.post( | ||
config_1.default.uris.userAuthenticate, | ||
{ | ||
RelyingParty: 'http://auth.xboxlive.com', | ||
TokenType: 'JWT', | ||
Properties: { | ||
AuthMethod: 'RPS', | ||
SiteName: 'user.auth.xboxlive.com', | ||
RpsTicket | ||
} | ||
}, | ||
{ | ||
headers: Object.assign( | ||
Object.assign({}, config_2.default.request.baseHeaders), | ||
{ Accept: 'application/json', 'x-xbl-contract-version': 0 } | ||
) | ||
} | ||
) | ||
.then(response => { | ||
if (response.status !== 200) | ||
throw errors_1.default.internal( | ||
'Could not exchange specified "RpsTicket"' | ||
); | ||
else return response.data; | ||
}) | ||
.catch(err => { | ||
if (!!err.__XboxReplay__) throw err; | ||
else throw errors_1.default.internal(err.message); | ||
}); | ||
exports.exchangeTokensForXSTSIdentity = ( | ||
{ userToken, deviceToken, titleToken }, | ||
{ XSTSRelyingParty, optionalDisplayClaims, raw } = {} | ||
) => | ||
axios_1.default | ||
.post( | ||
config_1.default.uris.XSTSAuthorize, | ||
{ | ||
RelyingParty: | ||
XSTSRelyingParty || config_1.default.defaultRelyingParty, | ||
TokenType: 'JWT', | ||
Properties: { | ||
UserTokens: [userToken], | ||
DeviceToken: deviceToken, | ||
TitleToken: titleToken, | ||
OptionalDisplayClaims: optionalDisplayClaims, | ||
SandboxId: 'RETAIL' | ||
} | ||
}, | ||
{ | ||
headers: Object.assign( | ||
Object.assign({}, config_2.default.request.baseHeaders), | ||
{ Accept: 'application/json', 'x-xbl-contract-version': 1 } | ||
) | ||
} | ||
) | ||
.then(response => { | ||
if (response.status !== 200) { | ||
throw errors_1.default.internal( | ||
'Could not exchange specified "userToken"' | ||
); | ||
} | ||
if (raw !== true) { | ||
const body = response.data; | ||
return { | ||
userXUID: body.DisplayClaims.xui[0].xid || null, | ||
userHash: body.DisplayClaims.xui[0].uhs, | ||
XSTSToken: body.Token, | ||
expiresOn: body.NotAfter | ||
}; | ||
} else return response.data; | ||
}) | ||
.catch(err => { | ||
var _a; | ||
if (!!err.__XboxReplay__) throw err; | ||
else if ( | ||
((_a = err.response) === null || _a === void 0 | ||
? void 0 | ||
: _a.status) === 400 | ||
) { | ||
const isDefaultRelyingParty = | ||
XSTSRelyingParty === config_1.default.defaultRelyingParty; | ||
const computedErrorMessage = [ | ||
'Could not exchange "userToken", please', | ||
`refer to ${config_2.default.gitHubLinks.seeUserTokenIssue}` | ||
]; | ||
if (isDefaultRelyingParty === false) | ||
computedErrorMessage.splice( | ||
1, | ||
0, | ||
'double check the specified "XSTSRelyingParty" or' | ||
); | ||
throw errors_1.default.internal(computedErrorMessage.join(' ')); | ||
} else throw errors_1.default.internal(err.message); | ||
}); | ||
exports.exchangeUserTokenForXSTSIdentity = (userToken, options) => | ||
exports.exchangeTokensForXSTSIdentity({ userToken }, options); |
@@ -1,2 +0,3 @@ | ||
import { exchangeRpsTicketForUserToken, exchangeUserTokenForXSTSIdentity } from './core/xboxlive'; | ||
import { preAuth, logUser } from './core/live'; | ||
import { exchangeRpsTicketForUserToken, exchangeUserTokenForXSTSIdentity, exchangeTokensForXSTSIdentity } from './core/xboxlive'; | ||
export declare type Credentials = { | ||
@@ -6,5 +7,15 @@ email: string; | ||
}; | ||
export declare type AuthOptions = { | ||
export declare type TokensExchangeProperties = { | ||
userToken: string; | ||
deviceToken?: string; | ||
titleToken?: string; | ||
}; | ||
export declare type TokensExchangeOptions = { | ||
XSTSRelyingParty?: string; | ||
optionalDisplayClaims?: string[]; | ||
raw?: boolean; | ||
}; | ||
export declare type AuthenticateOptions = { | ||
XSTSRelyingParty?: string; | ||
}; | ||
export declare type PreAuthResponse = { | ||
@@ -44,3 +55,3 @@ cookie: string; | ||
}; | ||
export declare const authenticate: (email: string, password: string, options?: AuthOptions) => Promise<AuthenticateResponse>; | ||
export { exchangeRpsTicketForUserToken, exchangeUserTokenForXSTSIdentity }; | ||
export declare const authenticate: (email: string, password: string, options?: AuthenticateOptions) => Promise<AuthenticateResponse>; | ||
export { preAuth, logUser, exchangeRpsTicketForUserToken, exchangeUserTokenForXSTSIdentity, exchangeTokensForXSTSIdentity }; |
@@ -13,5 +13,8 @@ "use strict"; | ||
const live_1 = require("./core/live"); | ||
exports.preAuth = live_1.preAuth; | ||
exports.logUser = live_1.logUser; | ||
const xboxlive_1 = require("./core/xboxlive"); | ||
exports.exchangeRpsTicketForUserToken = xboxlive_1.exchangeRpsTicketForUserToken; | ||
exports.exchangeUserTokenForXSTSIdentity = xboxlive_1.exchangeUserTokenForXSTSIdentity; | ||
exports.exchangeTokensForXSTSIdentity = xboxlive_1.exchangeTokensForXSTSIdentity; | ||
exports.authenticate = (email, password, options = {}) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -21,3 +24,3 @@ const preAuthResponse = yield live_1.preAuth(); | ||
const exchangeRpsTicketForUserTokenResponse = yield xboxlive_1.exchangeRpsTicketForUserToken(logUserResponse.access_token); | ||
return xboxlive_1.exchangeUserTokenForXSTSIdentity(exchangeRpsTicketForUserTokenResponse.Token, options.XSTSRelyingParty, false); | ||
return xboxlive_1.exchangeUserTokenForXSTSIdentity(exchangeRpsTicketForUserTokenResponse.Token, { XSTSRelyingParty: options.XSTSRelyingParty, raw: false }); | ||
}); |
{ | ||
"name": "@xboxreplay/xboxlive-auth", | ||
"description": "Simple Xbox Live authentication module.", | ||
"version": "3.0.2", | ||
"version": "3.1.1", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "xboxreplay", |
@@ -22,6 +22,6 @@ # Xbox Live - Auth | ||
{ | ||
"userXUID": "2535465515082324", // May be null | ||
"userHash": "1890318589445465111", | ||
"userXUID": "2584878536129841", // May be null | ||
"userHash": "3218841136841218711", | ||
"XSTSToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiWGJveFJlcGxheS5uZXQifQ.c2UraxPmZ4STYozrjFEW8SBqU0WjnIV0h-jjnfsKtrA", | ||
"expiresOn": "2019-04-05T05:43:32.6275675Z" | ||
"expiresOn": "2020-04-13T05:43:32.6275675Z" | ||
} | ||
@@ -43,3 +43,3 @@ ``` | ||
```shell | ||
$ curl 'https://profile.xboxlive.com/users/gt(Zeny%20IC)/profile/settings?settings=Gamerscore' \ | ||
$ curl 'https://profile.xboxlive.com/users/gt(Major%20Nelson)/profile/settings?settings=Gamerscore' \ | ||
-H 'Authorization: XBL3.0 x={userHash};{XSTSToken}' \ | ||
@@ -55,8 +55,8 @@ -H 'x-xbl-contract-version: 2' | ||
{ | ||
"id": "2500000000000000", | ||
"hostId": "2500000000000000", | ||
"id": "2584878536129841", | ||
"hostId": "2584878536129841", | ||
"settings": [ | ||
{ | ||
"id": "Gamerscore", | ||
"value": "1000000" | ||
"value": "911540" | ||
} | ||
@@ -63,0 +63,0 @@ ], |
18463
376