Skip to main content
The minecraft/auth package implements authentication to Microsoft Live Connect, XBOX Live, and Minecraft accounts. It provides OAuth2-style token sources for device authentication.

Functions

RequestMinecraftChain

func RequestMinecraftChain(ctx context.Context, token *XBLToken, key *ecdsa.PrivateKey) (string, error)
Requests a fully processed Minecraft JWT chain using an XSTS token and ECDSA private key. This chain is used during the login sequence for authentication.
ctx
context.Context
Context for the HTTP request
token
*XBLToken
The XBOX Live token to use for authentication
key
*ecdsa.PrivateKey
The client’s ECDSA private key (used for encryption initialization)
string
The encoded JWT chain ready for use in a login request
error
Error if the request fails

RequestXBLToken

func RequestXBLToken(ctx context.Context, liveToken *oauth2.Token, relyingParty string) (*XBLToken, error)
Requests an XBOX Live token using a Microsoft Live Connect token.
ctx
context.Context
Context for the HTTP request
liveToken
*oauth2.Token
The Microsoft Live Connect access token
relyingParty
string
The relying party URI (typically “https://multiplayer.minecraft.net/”)
*XBLToken
The XBOX Live token that can be used for Minecraft authentication

Types

XBLToken

type XBLToken struct {
    Token        string
    UserHash     string
    AuthorizationHeaderValue string
    ExpiresOn    time.Time
}
Represents an XBOX Live authentication token.

Methods

Valid
func (t *XBLToken) Valid() bool
Returns whether the token is still valid (not expired).
SetAuthHeader
func (t *XBLToken) SetAuthHeader(req *http.Request)
Sets the authorization header on an HTTP request using the token.

Token Sources

The package provides OAuth2-compatible token sources for device authentication:

TokenSource

func TokenSource(timeout time.Duration) oauth2.TokenSource
Creates a token source that uses device authentication flow. The user must visit a URL and enter a code to authenticate.
timeout
time.Duration
Maximum time to wait for user authentication
oauth2.TokenSource
A token source that can be used with minecraft.Dialer

Example Usage

Device Authentication

import (
    "github.com/sandertv/gophertunnel/minecraft"
    "github.com/sandertv/gophertunnel/minecraft/auth"
    "time"
)

// Create a token source with device auth
tokenSource := auth.TokenSource(time.Minute * 5)

// Use it with a dialer
dialer := minecraft.Dialer{
    TokenSource: tokenSource,
}

conn, err := dialer.Dial("raknet", "localhost:19132")
if err != nil {
    panic(err)
}
defer conn.Close()

Using Existing XBL Token

dialer := minecraft.Dialer{
    XBLToken: myExistingToken,
}

conn, err := dialer.Dial("raknet", "localhost:19132")