<p align="center"><img src="https://docs.sculk.network/nightly/assets/crates/oauthmc/docs/assets/banner.png" alt="OAuthMC by sculk.network: verify Minecraft Java accounts by joining a server" width="100%"></p>

# OAuthMC

OAuthMC is a standalone Rust service that verifies a player owns a Minecraft Java Edition account by having them join a Minecraft server. It runs an online-mode Minecraft listener alongside a private HTTP API, requires no database, and lets platforms verify accounts without Microsoft Entra app approval.

## How it works

1. Your platform creates a short-lived ticket for a Minecraft username over the HTTP API (`POST /v1/tickets`).
2. The player joins your OAuthMC server in Minecraft Java Edition. OAuthMC authenticates them against Mojang's session server and delivers a single-use 8-character code (`XXXX-XXXX`):
   - **Code mode** (all supported versions): disconnects the player with the code, which they enter on your platform.
   - **Link mode** (Minecraft 1.21.6+, automatic code-mode fallback on older versions): holds the player in Configuration with an in-game dialog (**Open link** and **Copy code**) and disconnects them with a confirmation message once redeemed.
3. Your platform redeems the code (`POST /v1/tickets/{id}/redeem`) to receive the player's Mojang UUID and canonical username.

```mermaid
sequenceDiagram
    participant Platform
    participant OAuthMC
    participant Player

    Platform->>OAuthMC: POST /v1/tickets {name}
    OAuthMC-->>Platform: 201 {id, address, expires_at}
    Platform-->>Player: Show server address
    Player->>OAuthMC: Join in Minecraft (online mode)
    OAuthMC-->>Player: Code disconnect or 1.21.6+ dialog
    Player->>Platform: Enter code or confirm link in signed-in session
    Platform->>OAuthMC: POST /v1/tickets/{id}/redeem {code}
    OAuthMC-->>Platform: 200 {uuid, name}
```

## Quick start

`ghcr.io/yellowumbrelladev/oauthmc` is not published yet; it ships with the first release. Build the container locally from `crates/oauthmc` (or `.` if you are already inside that directory):

```sh
docker build -t oauthmc crates/oauthmc
```

```text
 => => naming to docker.io/library/oauthmc:latest
```

Generate a 32+ character API key and start OAuthMC (binding port `8080` to loopback so the HTTP API stays private):

```sh
API_KEY=$(openssl rand -hex 24)
docker run -d --name oauthmc \
  -p 25565:25565 \
  -p 127.0.0.1:8080:8080 \
  -e OAUTHMC_API_KEYS="$API_KEY" \
  -e OAUTHMC_PUBLIC_ADDRESS="verify.example.com" \
  oauthmc
```

```text
<container id>
```

Create a ticket:

```sh
curl -sS -X POST http://127.0.0.1:8080/v1/tickets \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"HatsuneMiku"}'
```

```json
{"address":"verify.example.com","exclusive":false,"expires_at":"2026-11-26T10:32:09Z","id":"tkt_823fc8dac7451029a38794aef229ea24","max_attempts":5,"metadata":null,"mode":"code","name":"HatsuneMiku","status":"pending"}
```

Join `127.0.0.1:25565` in Minecraft Java Edition with that account to get your one-time code, then redeem it:

```sh
curl -sS -X POST http://127.0.0.1:8080/v1/tickets/tkt_823fc8dac7451029a38794aef229ea24/redeem \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"code":"N6AN-46TW"}'
```

```json
{"name":"HatsuneMiku","uuid":"a0c4b8c5-a04f-4a6f-9d02-1dea6154a9f6"}
```

For the full walkthrough with every step and status check, read [Getting started](https://docs.sculk.network/nightly/oauthmc/getting-started.md).

## Documentation

- [Documentation index and glossary](https://docs.sculk.network/nightly/oauthmc/index.md)
- [Getting started](https://docs.sculk.network/nightly/oauthmc/getting-started.md) — build, run, join, and redeem end to end
- [Integrating OAuthMC](https://docs.sculk.network/nightly/oauthmc/integrating.md) — code mode, link mode confirmation pages, polling, errors, SDK, and raw HTTP
- [Configuration](https://docs.sculk.network/nightly/oauthmc/configuration.md) — every `OAUTHMC_*` environment variable and message template
- [HTTP API](https://docs.sculk.network/nightly/oauthmc/api.md) — endpoints, schemas, and error codes ([OpenAPI spec](https://docs.sculk.network/nightly/oauthmc/openapi.md))
- [Deploying](https://docs.sculk.network/nightly/oauthmc/deploy.md) — Docker Compose, DNS SRV, TCP proxies, health checks, upgrades, and shutdown
- [Security model](https://docs.sculk.network/nightly/oauthmc/security.md) — threat model, session binding, tenant isolation, rate limits, and cryptography
- [Minecraft protocol](https://docs.sculk.network/nightly/oauthmc/protocol.md) — version matrix, packet quirks, and Configuration dialogs
- [TypeScript SDK](https://docs.sculk.network/nightly/oauthmc/sdk/js.md) — zero-dependency `oauthmc` client for Node.js 18+, Deno, Bun, and Cloudflare Workers
- [Contributing](https://docs.sculk.network/nightly/oauthmc/contributing.md) — building from source, Rust tests, client matrix, and releases

## Supported versions

Verified against real `node-minecraft-protocol` clients in online mode:

- **Code mode**: 1.8.9, 1.12.2, 1.16.5, 1.19, 1.19.2, 1.20.1, 1.21.1, and 26.1.
- **Link mode**: 1.21.6, 1.21.8, 1.21.11, and 26.1 (older clients fall back to code mode).

Protocol `776` (26.2) and `777` (26.3) are implemented from the protocol spec and verified by in-repo integration tests. See [Minecraft protocol](https://docs.sculk.network/nightly/oauthmc/protocol.md) for details.

## License

OAuthMC is licensed under the [MIT License](https://github.com/YellowUmbrellaDev/sculk.network/blob/96e9a1b/crates/oauthmc/LICENSE).

OAuthMC is not affiliated with or endorsed by Mojang Studios or Microsoft. Minecraft is a trademark of Mojang Studios.
