MojangUser

MojangUser

Type: Object

Properties
id (String) : user UUID
email (String)
firstName (String)
lastName (String)
username (String)
registerIp (String)
migratedFrom (String)
migratedAt (Number)
registeredAt (Number)
passwordChangedAt (Number)
dateOfBirth (Number)
deleted (Boolean)
blocked (Boolean)
secured (Boolean)
migrated (Boolean)
emailVerified (Boolean)
legacyUser (Boolean)
verifiedByParent (Boolean)
fullName (String)
fromMigratedUser (Boolean)
hashed (Boolean)

MojangChallenge

MojangChallenge

Type: Object

Properties
answer (Object)
question (Object)
  • question.id Number
  • question.question String

    text to prompt user with

MojangProfile

MojangProfile

Type: Object

Properties
id (String) : profile UUID
agent (String) : minecraft, scrolls
name (String) : in-game name (IGN)
userId (String) : user UUID
createdAt (Number)
legacyProfile (Boolean)
deleted (Boolean)
paid (Boolean)
migrated (Boolean)

MojangSession

MojangSession

Type: Object

Properties
clientToken (String)
accessToken (String)
selectedProfile ({id: String, name: String}?)
availableProfiles (Array<{id: String, name: String}>?)
user ({id: String}?) : always included by authenticate

CustomSession

CustomSession

Type: Object

Properties
id (String) : profile UUID
name (String) : in-game name (IGN)
timestamp (Number)
skin (String) : URL of the current skin texture
cape (String) : URL of the current cape texture
isSlim (Boolean) : true if profile is using slim model

status

Returns status of various Mojang services in a more helpful format.

status(): Promise<Array>
Returns
Promise<Array>: resolves a list like [{hostname, color, isAvailable, hasIssues}]

getProfile

Undocumented: Gets profile data for the given profile UUID.

getProfile(profileId: String): Promise<Object>
Parameters
profileId (String) profile UUID (does not work with user UUID)
Returns
Promise<Object>: resolves with {id, name, legacy?, demo?}

getProfileHistory

Gets all name changes for a given player's profile UUID.

getProfileHistory(profileId: String): Promise<Array<{name: String, changedToAt: Number}>>
Parameters
profileId (String) profile UUID (does not work with user UUID)
Returns
Promise<Array<{name: String, changedToAt: Number}>>: resolves if profile exists

lookupProfiles

Gets a list of abbreviated game profiles from the list of profile names.

It seems results are reordered alphabetically.

You cannot request more than 100 names per request.

lookupProfiles(names: Array<String>, agent: String?): Promise<Array>
Parameters
names (Array<String>) list of current profile names (IGN)
agent (String? = 'minecraft') game agent to search within (minecraft, scrolls)
Returns
Promise<Array>: resolves with [{id, name, legacy?, demo?}]
Example
async function getPaidMinecraftProfiles (names) {
  const list = await getProfiles(names)
  return list.filter(({demo}) => !demo)
}

lookupProfileAt

Gets an abbreviated game profile at a given timestamp for an IGN name.

Prefer lookupProfiles when looking up current data.

lookupProfileAt(name: String, date: Number?, agent: String?): Promise<Object>
Parameters
name (String) current profile name (IGN) of the user
date (Number?) UNIX timestamp to check the username at
agent (String? = 'minecraft') game agent to check against
Returns
Promise<Object>: resolves with {id, name, legacy?, demo?}
Example
const {id, name, legacy, demo} = await lookupProfileAt('Notch', 1503335853700)

getOrdersStatistics

Get statistics on the sales of Minecraft.

getOrdersStatistics(metricKeys: Array<String>?): Promise<Array<{total: Number, last24: Number, saleVelocityPerSeconds: Number}>>
Parameters
metricKeys (Array<String>? = ['item_sold_minecraft','prepaid_card_redeemed_minecraft']) list of metric keys to combine the stats of
Returns
Promise<Array<{total: Number, last24: Number, saleVelocityPerSeconds: Number}>>: resolves if metricKeys is provided

authenticate

Authenticates a user with their Mojang credentials.

Use agent if session is for a game client, ie. a Minecraft launcher.

Handle access tokens securely, but they do invalidate easily.

authenticate(credentials: Object): Promise<MojangSession>
Parameters
credentials (Object) the payload of the auth request
Name Description
credentials.username String email or username of a Mojang account
credentials.password String password for the given account
credentials.clientToken String? if empty, server will generate a client token
credentials.agent Object? if valid, adds selectedProfile to response
credentials.agent.name String name of the agent ('Minecraft' or 'Scrolls')
credentials.agent.version Number version number of the agent (use 1 )
Returns
Promise<MojangSession>: resolves if credentials are valid
Example
const clientToken = 'loaded from settings'
const agent = {name: 'Minecraft', version: 1}
const session = await mojang.authenticate({username, password, clientToken, agent})
console.debug('access token', session.accessToken)
console.debug('profile id', session.selectedProfile.id)
console.debug('minecraft ign', session.selectedProfile.name)
console.debug('user id', session.user.id)

isValid

Checks if an access token is suitable for use with a Minecraft server.

isValid(session: Object): Promise<Boolean>
Parameters
session (Object) a session access token
Name Description
session.accessToken String a session access token
session.clientToken String? must match the one used to obtain the access token
Returns
Promise<Boolean>: resolves true if tokens are valid
Example
if (await mojang.isValid(session)) {
  console.debug('access token still good')
} else {
  console.debug('access token has gone bad')
}

refresh

Refreshes a given access token. May work on invalid access tokens (about 1 token back in time).

refresh(session: Object): Promise<MojangSession>
Parameters
session (Object) a session access token
Name Description
session.accessToken String a session access token
session.clientToken String? must match the one used to obtain the access token
session.selectedProfile Object? use only with access tokens that were not assigned a game profile
session.selectedProfile.id String profile UUID
session.selectedProfile.name String profile name (IGN)
Returns
Promise<MojangSession>: resolves if the Mojang gods are feeling generous
Example
if (!await mojang.isValid(session)) {
  const nextSession = await mojang.refresh(session)
}

invalidate

Invalidate an access token.

invalidate(session: Object): Promise
Parameters
session (Object) a session to end/invalidate
Name Description
session.accessToken String a session access token
session.clientToken String? must match the one used to obtain the access token
Returns
Promise: always resolves, regardless if tokens were valid
Example
const session = await mojang.authenticate(credentials)
console.log('logged in', session.selectedProfile.name)
await mojang.invalidate(session)
console.log('logged out')

signout

Invalidates access tokens of a given Mojang account.

signout(credentials: Object): Promise
Parameters
credentials (Object) account credentials
Name Description
credentials.username String email or username of a Mojang account
credentials.password String password for the given account
Returns
Promise: resolves only if credentials were correct
Example
mojang.signout({username, password})
  .then(() => console.log('user signed out'))
  .catch(err => console.error(err))

isSecure

Undocumented: Gets a logged-in user's IP security status for the current IP.

isSecure(session: Object): Promise<Boolean>
Parameters
session (Object) object from authentication
Name Description
session.accessToken String valid access token for the user's account
Returns
Promise<Boolean>: resolves true if current IP is secure
Example
const canChangeSkins = await isSecure(accessToken)

getChallenges

Undocumented: Gets a logged-in user's security challenge questions.

getChallenges(session: Object): Promise<Array<MojangChallenge>>
Parameters
session (Object) object from authentication
Name Description
session.accessToken String valid access token for the user's account
Returns
Promise<Array<MojangChallenge>>: resolves if access token is valid

answerChallenges

Undocumented: Submits a logged-in user's security challenge answers to trust the current IP.

answerChallenges(session: Object, answers: Array): Promise
Parameters
session (Object) object from authentication
Name Description
session.accessToken String valid access token for the user's account
answers (Array) list of answers like [{id, answer}]
Returns
Promise: resolves if location was secured
Example
const challenges = await getChallenges(session)
const answers = await Promise.all(challenges.map(async c => {
  const answer = await prompt(c.question.question)
  return {id: c.answer.id, answer}
}))
await answerChallenges(session, answers) // might throw
await isSecure(session) // true if successful

getSession

A special service that returns a profile's name, skin URL, and cape URL.

This endpoint is used by the official launcher to load the current skin.

Rate limit: You can request the same profile once per minute.

getSession(profileId: String): Promise<CustomSession>
Parameters
profileId (String) profile UUID of a player
Returns
Promise<CustomSession>: resolves if profile exists

getBlockedServers

Returns a list of SHA1 hashes used to check server addresses against when the client tries to connect.

See http://wiki.vg/Mojang_API#Blocked_Servers for how this list is used.

getBlockedServers(): Promise<Array<String>>
Returns
Promise<Array<String>>: resolves to a list of address hashes

getUser

Gets a logged-in user's private Mojang account information.

getUser(session: Object): Promise<MojangUser>
Parameters
session (Object) object from authentication
Name Description
session.accessToken String valid access token for the user's account
Returns
Promise<MojangUser>: resolves if access token is valid

setSkin

Sets a logged-in user's in-game skin to an online image.

setSkin(session: Object, profileId: String, skinUrl: String, isSlim: Boolean?): Promise
Parameters
session (Object) object from authentication
Name Description
session.accessToken String valid access token for the user's account
profileId (String) which profile UUID to update the skin of
skinUrl (String) Internet-accessible URL of the image file
isSlim (Boolean? = false) if true, the slim model will be used with the skin
Returns
Promise: resolves if access token, profile UUID, and skin URL are valid

resetSkin

Resets/deletes a logged-in user's in-game skin.

resetSkin(session: Object, profileId: String): Promise
Parameters
session (Object) object from authentication
Name Description
session.accessToken String valid access token for the user's account
profileId (String) which profile UUID to update the skin of
Returns
Promise: resolves if skin was deleted/reset

getUserProfiles

Undocumented: Gets a list of all of a logged-in user's game profiles.

getUserProfiles(session: Object): Promise<Array<MojangProfile>>
Parameters
session (Object) object from authentication
Name Description
session.accessToken String valid access token for the user's account
Returns
Promise<Array<MojangProfile>>: resolves if access token is valid

getUserCapeData

Undocumented: Gets a logged-in user's capes for a given profile.

I have no idea what this endpoint returns!

getUserCapeData(session: Object, profileId: String): Promise<Array>
Parameters
session (Object) object from authentication
Name Description
session.accessToken String valid access token for the user's account
profileId (String) game profile UUID to look for capes in
Returns
Promise<Array>: resolves with an array of something