Skip to content

Minecraft Bedrock Authentication library written in Zig.

Notifications You must be signed in to change notification settings

SanctumTerra/auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AUTH

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.

Features

  • 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.

Usage

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});
}

Installation

Add this package to your project:

zig fetch --save git+https://github.com/SanctumTerra/auth.git

And in your build.zig:

const auth_dep = b.dependency("AUTH", .{
    .target = target,
    .optimize = optimize,
});
mod.addImport("AUTH", auth_dep.module("AUTH"));

Dependencies

  • zlib: Required for GZIP compression/decompression of API payloads.

About

Minecraft Bedrock Authentication library written in Zig.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages