# prismarine-auth

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

Latest version **3.1.1** (published 2026-03-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install prismarine-auth
pnpm add prismarine-auth
yarn add prismarine-auth
bun add prismarine-auth
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2026-03-31 |
| First published | 2021-08-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 91 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 75 |
| Author | Romain Beaumont |
| Maintainers | rom1504 |
| Keywords | prismarine, template |

## Links

- npm: https://www.npmjs.com/package/prismarine-auth
- Repository: https://github.com/PrismarineJS/prismarine-auth
- Homepage: https://github.com/PrismarineJS/prismarine-auth#readme
- Issues: https://github.com/PrismarineJS/prismarine-auth/issues
- npm.io page: https://npm.io/package/prismarine-auth

## Dependencies (5)

- [debug](https://npm.io/package/debug.md) ^4.3.3
- [uuid-1345](https://npm.io/package/uuid-1345.md) ^1.0.2
- [smart-buffer](https://npm.io/package/smart-buffer.md) ^4.1.0
- [@azure/msal-node](https://npm.io/package/@azure/msal-node.md) ^2.0.2
- [@xboxreplay/xboxlive-auth](https://npm.io/package/@xboxreplay/xboxlive-auth.md) ^5.1.0

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 3.1.1 (latest) — 2026-03-31
- 3.1.0 — 2026-03-30
- 3.0.0 — 2026-03-29
- 2.7.0 — 2025-02-26
- 2.6.0 — 2025-01-19
- 2.5.1 — 2024-12-28
- 2.5.0 — 2024-05-29
- 2.4.2 — 2024-04-12
- 2.4.1 — 2024-02-15
- 2.4.0 — 2024-01-03
- 2.3.0 — 2023-09-27
- 2.2.0 — 2023-01-14
- 2.1.1 — 2022-12-09
- 2.1.0 — 2022-11-11
- 2.0.1 — 2022-10-23
- … 19 more at https://npm.io/package/prismarine-auth/versions

## README

# prismarine-auth
[![NPM version](https://img.shields.io/npm/v/prismarine-auth.svg)](http://npmjs.com/package/prismarine-auth)
[![Build Status](https://github.com/PrismarineJS/prismarine-auth/workflows/CI/badge.svg)](https://github.com/PrismarineJS/prismarine-auth/actions?query=workflow%3A%22CI%22)
[![Official Discord](https://img.shields.io/static/v1.svg?label=PrismarineJS&message=Discord&color=blue&logo=discord)](https://discord.gg/GsEFRM8)
[![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/prismarine-auth)

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

## Installation
```shell
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](docs/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](docs/API.md)
    - [deviceType] {string} - See the [API.md](docs/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
```js
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:

```js
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](./index.d.ts) for more information.

### getXboxToken
See [docs/API.md](docs/API.md)


### getMinecraftJavaToken
```js
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
```json
{
    "token": "ey....................",
    "entitlements": {},
    "profile": {
        "id": "b945b6ed99b548675309473a69661b9a",
        "name": "Usname",
        "skins": [ [Object] ],
        "capes": []
    }
}
```

### getMinecraftBedrockToken
See [docs/API.md](docs/API.md) and [example](examples).
It returns an object with `{ chain, token }` for Bedrock login.

### getMinecraftBedrockChain
See [docs/API.md](docs/API.md).

### getMinecraftBedrockMultiplayerToken
See [docs/API.md](docs/API.md).

### getMinecraftBedrockServicesToken
```js
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
```json
{
    "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](https://github.com/PrismarineJS/prismarine-auth/tree/master/examples).

See the [types](./index.d.ts) to checkout the full API.

## API

See [docs/API.md](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](LICENSE)

---
_Source: https://npm.io/package/prismarine-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
