export interface XBoxResponse { IssueInstant: string; NotAfter: string; Token: string; DisplayClaims: { xui: [ { /** * gamer tag */ gtg: string; /** * user id */ xid: string; uhs: string; } ]; }; } export interface XBoxPresenceRecord { xuid: string; state: 'Online' | 'Offline' | 'Away' | string; devices?: Array<{ type: string; titles?: Array<{ id: number; name: string; placement?: string; state?: string; }>; }>; } export interface XBoxPresenceResponse { userPresence?: XBoxPresenceRecord[]; } export interface XBoxGameProfileResponse { profileUsers: [ { id: string; hostId: string | null; settings: [ { id: 'Gamertag'; value: string; }, { id: 'PublicGamerpic'; value: string; } ]; isSponsoredUser: boolean; } ]; } export interface MinecraftAuthResponse { username: string; roles: []; access_token: string; token_type: 'Bearer'; expires_in: number; } export interface MicrosoftAuthenticatorOptions { fetch?: typeof fetch; xboxDeviceTokenStorage?: XboxDeviceTokenStorage; } export interface XboxDeviceTokenState { id: string; privateKey: JsonWebKey; token?: Pick; } export interface XboxDeviceTokenStorage { get(): Promise; put(state: XboxDeviceTokenState): Promise; } /** * Thrown by {@link MicrosoftAuthenticator.loginMinecraftWithXBox} when the * Minecraft auth endpoint returns a non-200 response. Carries enough * context that the launcher can tell the user *exactly* what went wrong * instead of a generic "loginMinecraftByXboxFailed" (see issue #1445). * * Retry semantics (for 408/425/429/5xx) are intentionally out of scope of * this module -- compose them on the caller side by wrapping the injected * `fetch` (see ``xmcl-runtime/user/utils/withRetry.ts`` in the launcher). */ export declare class MicrosoftMinecraftXboxLoginError extends Error { status: number; body: string; /** Effective Retry-After in ms from the response header, if any. */ retryAfter?: number | undefined; /** * True when the status is in the transient set a retrying client would * normally retry (408/425/429/5xx). Useful to tell the user "try again * in a moment" vs. "this is a permanent error". */ retryable?: boolean | undefined; name: string; constructor(status: number, body: string, /** Effective Retry-After in ms from the response header, if any. */ retryAfter?: number | undefined, /** * True when the status is in the transient set a retrying client would * normally retry (408/425/429/5xx). Useful to tell the user "try again * in a moment" vs. "this is a permanent error". */ retryable?: boolean | undefined); } /** * The microsoft authenticator for Minecraft (Xbox) account. */ export declare class MicrosoftAuthenticator { fetch: typeof fetch; private xboxDeviceTokenStorage?; private xboxDeviceTokenState; private xboxDeviceTokenStateLoaded; private xboxDeviceTokenTask; constructor(options?: MicrosoftAuthenticatorOptions); /** * Authenticate with xbox live by ms oauth access token * @param oauthAccessToken The oauth access token */ authenticateXboxLive(oauthAccessToken: string, signal?: AbortSignal): Promise; authenticateXboxDevice(signal?: AbortSignal): Promise>; private loadXboxDeviceTokenState; private acquireXboxDeviceToken; /** * Authorize the xbox live. It will get the xsts token in response. * @param xblResponseToken The {@link XBoxResponse.Token} */ authorizeXboxLive(xblResponseToken: string, relyingParty?: 'rp://api.minecraftservices.com/' | 'http://xboxlive.com', signal?: AbortSignal, deviceToken?: string): Promise; /** * Get xbox user profile, including **username** and **avatar**. * * You can find the parameters from the {@link XBoxResponse}. * * @param xuid The `xuid` in a {@link XBoxResponse.DisplayClaims} * @param uhs The `uhs` in a {@link XBoxResponse.DisplayClaims} * @param xstsToken The {@link XBoxResponse.Token} * @returns The user game profile. */ getXboxGameProfile(xuid: string, uhs: string, xstsToken: string, signal?: AbortSignal): Promise; /** * Fetch Xbox Live presence status for a list of xuids or single xuid. * * @param xuids Array of Xbox User IDs (xuid) * @param uhs The `uhs` in {@link XBoxResponse.DisplayClaims} * @param xstsToken The {@link XBoxResponse.Token} */ getXboxPresence(xuids: string[], uhs: string, xstsToken: string, signal?: AbortSignal): Promise; /** * Acquire both Minecraft and xbox token and xbox game profile. * You can use the xbox token to login Minecraft by {@link loginMinecraftWithXBox}. * * This method is the composition of calling * - {@link authenticateXboxLive} * - {@link authorizeXboxLive} to `rp://api.minecraftservices.com/` * - {@link authorizeXboxLive} to `http://xboxlive.com` * - {@link getXboxGameProfile} * * You can call them individually if you want a more detailed control. * * @param oauthAccessToken The microsoft access token * @param signal The abort signal * @returns The object contain xstsResponse (minecraft xbox token) and xbox game profile */ acquireXBoxToken(oauthAccessToken: string, signal?: AbortSignal): Promise<{ minecraftXstsResponse: XBoxResponse; liveXstsResponse: XBoxResponse | undefined; }>; /** * This will return the response with Minecraft access token! * * This access token allows us to launch the game, but, we haven't actually checked if the account owns the game. Everything until here works with a normal Microsoft account! * * @param uhs uhs from {@link XBoxResponse} of {@link acquireXBoxToken} * @param xstsToken You need to get this token from {@link acquireXBoxToken} */ /** * Login Minecraft with an Xbox token. This method does exactly one HTTP * attempt -- if you need retry/backoff for transient failures (408, 425, * 429, 5xx), compose it on the caller side by wrapping the `fetch` you * inject into this authenticator. On any non-200 the method throws a * {@link MicrosoftMinecraftXboxLoginError} that carries `status`, * `body`, parsed `retryAfter` (ms) and a `retryable` flag so the UI can * surface a precise message (see issue #1445). * * @param uhs uhs from {@link XBoxResponse} of {@link acquireXBoxToken} * @param xstsToken You need to get this token from {@link acquireXBoxToken} */ loginMinecraftWithXBox(uhs: string, xstsToken: string, signal?: AbortSignal): Promise; } //# sourceMappingURL=microsoft.d.ts.map