Microsoft Authentication Library for Minecraft Bedrock Edition, written in Zig.
This library handles the complete Microsoft/Xbox Live authentication flow required for connecting to Minecraft Bedrock Edition servers.
- Device Code Login: OAuth2.0 device flow implementation.
- Xbox Authentication: Device authentication and SISU authorization.
- PlayFab Integration: XSTS token retrieval and PlayFab login.
- Minecraft Auth: Retrieval of the Minecraft authentication chain.
- Session Management: Session start and multiplayer session signing.
- Token Caching: Automatically caches tokens to disk to minimize re-authentication.
const std = @import("std");
const MicrosoftAuth = @import("AUTH").MicrosoftAuth;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
// Initialize with allocator and Game Version (e.g. "1.21.0")
var auth = try MicrosoftAuth.init(allocator, "1.21.0");
defer auth.deinit();
// Perform the complete authentication flow
// This will prompt for device code login on the console if no cached tokens exist
try auth.authenticate();
// Retrieve the results
const chain = auth.getMinecraftChain();
const signed_token = auth.getSignedToken();
const xbox_user_id = auth.getXboxUserId();
std.debug.print("Successfully authenticated as user: {s}\n", .{xbox_user_id});
}Add this package to your project:
zig fetch --save git+https://github.com/SanctumTerra/auth.gitAnd in your build.zig:
const auth_dep = b.dependency("AUTH", .{
.target = target,
.optimize = optimize,
});
mod.addImport("AUTH", auth_dep.module("AUTH"));- zlib: Required for GZIP compression/decompression of API payloads.