Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

prismarine-auth

PrismarineJS37.5kMIT2.7.0TypeScript support: included

Authentication library for Microsoft, Xbox Live, and Minecraft with caching support

prismarine, template

readme

prismarine-auth

NPM version Build Status Official Discord Try it on gitpod

Quickly and easily obtain auth tokens to authenticate with Microsoft/Xbox/Minecraft/Mojang

Installation

npm install prismarine-auth

Usage

Authflow

Parameters

  • username? {String} - Username for authentication
  • cacheDirectory? {String | Function} - Where we will store your tokens (optional) or a factory function that returns a cache.
  • options {Object?}
    • [flow] {enum} Required if options is specified - see API.md for options
    • [forceRefresh] {boolean} - Clear all cached tokens for the specified username to get new ones on subsequent token requests
    • [password] {string} - If passed we will do password based authentication.
    • [authTitle] {string} - See the API.md
    • [deviceType] {string} - See the API.md
  • onMsaCode {Function} - (For device code auth) What we should do when we get the code. Useful for passing the code to another function.

Examples

getMsaToken

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

const userIdentifier = 'unique identifier for caching'
const cacheDir = './' // You can leave this as undefined unless you want to specify a caching directory
const flow = new Authflow(userIdentifier, cacheDir)
// Get a auth token, then log it
flow.getMsaToken().then(console.log)

Note: By default, this library will authenticate as Minecraft for Nintendo Switch, with a flow set to live. For non-Minecraft applications you should register for Microsoft Azure Oauth token. See https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app#register-an-application for more information on obtaining an Azure token. You then use it with the msal flow like this:

const flow = new Authflow(userIdentifier, cacheDir, { flow: 'msal', authTitle: '000-000-000-000' })

If flow is live, the default, then you can only specify existing Microsoft client IDs. This library exposes some default Microsoft client IDs under the exported Titles object. See the types for more information.

getXboxToken

See docs/API.md

getMinecraftJavaToken

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

const userIdentifier = 'any unique identifier'
const cacheDir = './' // You can leave this as undefined unless you want to specify a caching directory
const flow = new Authflow(userIdentifier, cacheDir)
// Get a Minecraft Java Edition auth token, then log it
flow.getMinecraftJavaToken({ fetchProfile: true }).then(console.log)

Expected Response

{
    "token": "ey....................",
    "entitlements": {},
    "profile": {
        "id": "b945b6ed99b548675309473a69661b9a",
        "name": "Usname",
        "skins": [ [Object] ],
        "capes": []
    }
}

getMinecraftBedrockToken

See docs/API.md and example.

getMinecraftBedrockServicesToken

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

const userIdentifier = 'any unique identifier'
const cacheDir = './' // You can leave this as undefined unless you want to specify a caching directory
const flow = new Authflow(userIdentifier, cacheDir)
// Get a Minecraft Services token, then log it
flow.getMinecraftBedrockServicesToken().then(console.log)

Expected Response

{
    "mcToken": "MCToken eyJ...",
    "validUntil": "1970-01-01T00:00:00.000Z",
    "treatments": [
      "mc-enable-feedback-landing-page",
      "mc-store-enableinbox",
      "mc-nps-freeorpaid-paidaug24",
      // and more
    ],
    "configurations": {
      "validation": {
        "id": "Validation",
        "parameters": {
          "minecraftnetaatest": "false"
        }
      },
      "minecraft": {
        "id": "Minecraft",
        "parameters": {
          "with-spongebobadd-button-noswitch": "true",
          "sfsdfsdfsfss": "true",
          "fsdfd": "true",
          "mc-maelstrom-disable": "true",
          // and more
        }
      }
    },
    "treatmentContext": "mc-sunsetting_5:31118471;mc-..."
}

More

View more examples here.

See the types to checkout the full API.

API

See docs/API.md

Debugging

You can enable some debugging output using the DEBUG enviroment variable. Through node.js, you can add process.env.DEBUG = 'prismarine-auth' at the top of your code.

Testing

Simply run npm test or yarn test

License

MIT

changelog

History

2.7.0

2.6.0

2.5.1

2.5.0

2.4.2

2.4.1

2.4.0

2.3.0

2.2.0

  • Add mcpc chat report method

2.1.1

  • Fix typings

2.1.0

  • include signatureV2 (@jtsiskin)

2.0.1

  • Update docs

2.0.0

  • BREAKING : Add flow option (#55) @LucienHH
    • flow argument now required to explicitly specify what authentication flow (alternative endpoints for authentication) to use when instantiating Authflow. Supported options are live, msal, sisu ; see documentation for more information. Set this to msal if you have an custom Azure client token or live if you want to login as a official Microsoft app (like vanilla Minecraft client).

1.7.0

  • Breaking: Abstract fetchCertificates in MinecraftJavaTokenManager (#52)

1.6.0

  • Add fetchCertificates option to getMinecraftJavaToken

1.5.4

  • XboxTokenManager: Combine getXSTSToken & getXSTSTokenWithTitle and implement own getUserToken (#47)

1.5.3

  • Fix web request error logging expecting JSON response @LucienHH
  • Add exception messages for more Xbox API errors @Kashalls

1.5.2

  • Don't log authentication prompt if codeCallback is specified. (#40) - @ATXLtheAxolotl

1.5.1

  • Update User-Agent header @LucienHH

1.5.0

  • Move relyingParty option from constructor to getXboxToken(relyingParty?: string) (#34)
  • Fixed a bug that would cause refreshing the MSA token to error due to an undefined function

1.4.2

  • add debug dependency (#31) - @safazi

1.4.1

  • Correct missing await statement in live token refreshing (#29) - @dustinrue

1.4.0

  • Allow to use a custom cache instead of using the filesystem only (#26) - @Paulomart
  • Replace fs.rmdirSync with fs.rmSync (#25)
  • Add doSisuAuth option (#24)

1.3.0

  • Add deviceType and deviceVersion options to Authflow options #21

1.2.1

  • bump jose dep

1.2.0

  • Improve error handling (#15)
  • Fix caching, relyingParty issue (#13)
  • Documentation updates, see API usage.

1.1.2

  • proper fix

1.1.1

  • fix jose dep

1.1.0

  • Added entitlement and profile checks for Minecraft Java Token
  • Fixed bug when fetching only the xbox token
  • Added examples
  • Added index.d.ts

1.0.0

  • initial implementation