npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prismarine-auth

v2.5.0

Published

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

Downloads

27,658

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().then(console.log)

Expected Response

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

getMinecraftBedrockToken

See docs/API.md and example.

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