JSPM

  • Created
  • Published
  • Downloads 50475
  • Score
    100M100P100Q145972F
  • License MIT

A package to authenticate with xbox live and microsoft + cache tokens.

Package Exports

  • prismarine-auth

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (prismarine-auth) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

prismarine-auth

NPM version Build Status Discord Try it on gitpod

Quickly and easily obtain an xbox token to authenticate with Minecraft/Mojang

Installation

npm install prismarine-auth

Getting A Minecraft Java Token

Device Code Authentication

const { Authflow } = require('prismarine-auth');

const doAuth = async() => {
    const flow = new Authflow('mineflayer@is.cool', './')
    const XSTSToken = await flow.getMinecraftJavaToken()
    console.log(XSTSToken)
}

doAuth()

Password-based Authentication

const { Authflow } = require('prismarine-auth');

const doAuth = async() => {
    const flow = new Authflow('mineflayer@is.cool', './', { password: 'thisIsAFakePassword123'})
    const XSTSToken = await flow.getMinecraftJavaToken()
    console.log(XSTSToken)
}

doAuth()

Getting A Minecraft Bedrock Token

When authenticating for minecraft bedrock edition, you have to generate and send a signed certificate to the bedrock server. This function handles logging into Xbox Live, posting its public key to the Mojang API, and using the returned certificate signed by Mojang.

Device Code Authentication

const { Authflow } = require('prismarine-auth');
const crypto = require('crypto')
const curve = 'secp384r1'

const keypair = crypto.generateKeyPairSync('ec', { namedCurve: curve }).toString('base64') 
const doAuth = async() => {
    const flow = new Authflow('mineflayer@is.cool', './')
    const XSTSToken = await flow.getMinecraftBedrockToken(keypair)
    console.log(XSTSToken)
}

doAuth()

Password Authentication:

const { Authflow } = require('prismarine-auth');
const crypto = require('crypto')
const curve = 'secp384r1'

const keypair = crypto.generateKeyPairSync('ec', { namedCurve: curve }).toString('base64') 

const doAuth = async() => {
    const flow = new Authflow('mineflayer@is.cool', './', { password: 'thisIsAFakePassword123'})
    const XSTSToken = await flow.getMinecraftBedrockToken(keypair)
    console.log(XSTSToken)
}

doAuth()

Live.com Authentication with Titles

Device Code Authentication

const { Authflow, Titles } = require('prismarine-auth');
const crypto = require('crypto')
const curve = 'secp384r1'

const keypair = crypto.generateKeyPairSync('ec', { namedCurve: curve }).toString('base64') 
const doAuth = async() => {
    const flow = new Authflow('mineflayer@is.cool', './', { authTitle: Titles.MinecraftNintendoSwitch })
    const XSTSToken = await flow.getMinecraftBedrockToken(keypair)
    console.log(XSTSToken)
}

doAuth()

Password Authentication

const { Authflow , Titles} = require('prismarine-auth');
const crypto = require('crypto')
const curve = 'secp384r1'

const keypair = crypto.generateKeyPairSync('ec', { namedCurve: curve }).toString('base64') 

const doAuth = async() => {
    const flow = new Authflow('mineflayer@is.cool', './', { password: 'thisIsAFakePassword123', authTitle: Titles.MinecraftJava })
    const XSTSToken = await flow.getMinecraftBedrockToken(keypair)
    console.log(XSTSToken)
}

doAuth()

Expected Response

{
    "userXUID": "2584878536129841", // May be null
    "userHash": "3218841136841218711",
    "XSTSToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiWGJveFJlcGxheS5uZXQifQ.c2UraxPmZ4STYozrjFEW8SBqU0WjnIV0h-jjnfsKtrA",
    "expiresOn": "2020-04-13T05:43:32.6275675Z"
}

Parameters

Authflow class

  • username {String} - Username for authentication
  • cacheDirectory {String} - Where we will store your tokens
  • options {Object?}
    • [password] {string} - If passed we will do password based authentication.
    • [authTitle] {string} - Required to switch to live.com authentication and do title authentication. Needed for accounts with a date of birth under 18 years old.
  • onMsaCode {Function} - What we should do when we get the code. Useful for passing the code to another function.