Appearance
@loontail/minecraft-kit v0.8.14 / MojangAuthApi
Class: MojangAuthApi
High-level Microsoft / Mojang auth surface attached to MinecraftKit as kit.auth. Sign-in uses the OAuth 2.0 Authorization Code + PKCE flow with a loopback redirect (kit.auth.authorizationCode): the kit opens a localhost server, the caller opens the system browser, the user signs in, and the browser redirects back. The flow continues through the Xbox → XSTS → Minecraft pipeline and returns a MojangSession carrying everything launch composition needs plus the Microsoft refresh token. The library does NOT persist tokens — that's the caller's job.
Example
ts
import { MinecraftKit, toOnlineAuth } from "@loontail/minecraft-kit";
const kit = new MinecraftKit();
const session = await kit.auth.authorizationCode.run({
onOpenBrowser: (url) => open(url),
});
await saveRefreshToken(session.microsoft.refreshToken);
const launch = await kit.launch.compose(target, { auth: toOnlineAuth(session) });Constructors
new MojangAuthApi()
ts
new MojangAuthApi(http, logger?): MojangAuthApiParameters
| Parameter | Type |
|---|---|
http | HttpClient |
logger? | Logger |
Returns
Source
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
authorizationCode | readonly | { run: (options) => Promise<MojangSession>; } | ... | OAuth 2.0 Authorization Code + PKCE with loopback redirect. The kit binds a temporary HTTP server on 127.0.0.1:<random>, hands the caller an https://login.microsoftonline.com/... URL to open in the system browser, captures the redirect, and finishes the full pipeline.
|
authorizationCode.run | readonly | (options: AuthorizationCodeRunOptions) => Promise<MojangSession> | ... | - |
profile | public | { read: (input) => Promise<MinecraftProfile>; resetSkin: (input) => Promise<MinecraftProfile>; setSkinFromUrl: (input) => Promise<MinecraftProfile>; uploadSkin: (input) => Promise<MinecraftProfile>; } | ... | Player profile against (post-mutation) MinecraftProfile snapshot so a launcher can refresh its UI without an extra GET round-trip. Example import { MinecraftKit } from "@loontail/minecraft-kit"; |
profile.read | public | (input: ReadProfileInput) => Promise<MinecraftProfile> | ... | - |
profile.resetSkin | public | (input: ResetSkinInput) => Promise<MinecraftProfile> | ... | - |
profile.setSkinFromUrl | public | (input: SetSkinFromUrlInput) => Promise<MinecraftProfile> | ... | - |
profile.uploadSkin | public | (input: UploadSkinInput) => Promise<MinecraftProfile> | ... | - |
Methods
refresh()
ts
refresh(refreshToken, options): Promise<MojangSession>Refresh a previously obtained session. The Microsoft refresh token may be rotated.
Parameters
| Parameter | Type |
|---|---|
refreshToken | MicrosoftRefreshToken |
options | RefreshOptions |
Returns
Promise<MojangSession>