Microsoft OAuth2 Authentication

Overview

Microsoft authentication implements the OAuth 2.0 Device Code Flow to authenticate Minecraft accounts through:

  1. Microsoft Identity Platform

  2. Xbox Live

  3. Minecraft Services

This is the official authentication method for legitimate Minecraft accounts since Microsoft acquired Mojang.

Prerequisites

Azure AD Application

You need to register an application in Azure Active Directory:

  1. Navigate to Azure Active DirectoryApp registrations

  2. Click New registration

  3. Set Supported account types to "Accounts in any organizational directory and personal Microsoft accounts"

  4. No redirect URI needed (Device Code Flow)

  5. After registration, copy the Application (client) ID

Required Permissions

  • XboxLive.signin - Access to Xbox Live services

  • offline_access - Refresh tokens (optional but recommended)

Quick Start

Authentication Flow

Step-by-Step Process

spinner

1. Request Device Code

2. Display Code to User

The user must:

  1. Visit https://microsoft.com/devicelogin in a browser

  2. Enter the user_code (e.g., "ABCD1234")

  3. Sign in with their Microsoft account

  4. Authorize the application

3. Poll for Access Token

4. Exchange for Xbox Live Token

5. Exchange for XSTS Token

Possible Errors:

  • 2148916233: Account doesn't own Minecraft

  • 2148916238: Xbox Live not available in user's country

6. Exchange for Minecraft Token

7. Fetch Minecraft Profile

Configuration

Polling Interval

Control how often to check for authorization:

Timeout

Set maximum time to wait for user authorization:

Device Code Callback

Display the code to the user:

Error Handling

Event System Integration

Track authentication progress with events:

Events Emitted:

  1. AuthenticationStarted { provider: "Microsoft" }

  2. AuthenticationInProgress { step: "Requesting device code" }

  3. AuthenticationInProgress { step: "Waiting for user authorization" }

  4. AuthenticationInProgress { step: "Exchanging for Xbox Live token" }

  5. AuthenticationInProgress { step: "Exchanging for XSTS token" }

  6. AuthenticationInProgress { step: "Exchanging for Minecraft token" }

  7. AuthenticationInProgress { step: "Fetching Minecraft profile" }

  8. AuthenticationSuccess { username: "...", uuid: "..." }

Token Management

Access Token Storage

Token Refresh

Microsoft tokens include refresh tokens (with offline_access scope):

UserProfile Output

Best Practices

Callback Design

Retry Logic

Testing

Troubleshooting

Issue: Device code expires before user completes

Solution: Increase timeout

Issue: User doesn't see device code

Solution: Ensure callback is set before authenticate()

Issue: "Account doesn't own Minecraft" error

Solution: User needs to purchase Minecraft Java Edition

Issue: "Xbox Live not available" error

Solution: User is in a region where Xbox Live is blocked (e.g., certain countries)

Performance

Typical authentication duration: 30-60 seconds

Breakdown:

  • Device code request: ~500ms

  • User authorization: 20-50s (varies by user)

  • Token exchange (4 requests): ~2-5s

  • Profile fetch: ~200ms

Security Considerations

  • Client ID is public: Safe to embed in application

  • No client secret needed: Device Code Flow doesn't require secrets

  • Tokens should be encrypted: Store access tokens securely

  • HTTPS only: All requests use HTTPS

  • Token expiration: Minecraft tokens expire after 24 hours

Last updated