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.
Context for the HTTP request
The XBOX Live token to use for authentication
The client’s ECDSA private key (used for encryption initialization)
The encoded JWT chain ready for use in a login request
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.
Context for the HTTP request
The Microsoft Live Connect access token
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.
Maximum time to wait for user authentication
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")