Giter Club home page Giter Club logo

minecraft-authenticator's Introduction

Minecraft Authenticator

If you need mojang authentication or java 8 support please have a look at branch 1.x and 2.x

A minecraft authentication library that allows microsoft (xbox live) accounts to be logged in and returns a minecraft profile with an access token as well as xbox profile settings. This library also allows for storage of the authentication data and therefore sessions can be refreshed without a new login on the users side.

Building

To build just run ./gradlew build. You will find the jars in the build/libs directory. This project requires gson and java 17 as dependency.

Include in your own project

To include this project you can use the maven build of this project which will resolve all required dependencies automatically. The latest version is the latest tag in github.

repositories {
	maven {
		url = "https://repo.u-team.info"
	}
}

dependencies {
	implementation "net.hycrafthd:minecraft_authenticator:XYZ"
}

Usage

The main public facing api is the Authenticator class. This class is documented and you should have a look here about more information. The following code snippets are just some simple usage demonstrations.

Here is a simple login with microsoft

// Build authenticator
final Authenticator authenticator = Authenticator.ofMicrosoft(authorizationCode).shouldAuthenticate().build();
try {
	// Run authentication
	authenticator.run();
} catch (final AuthenticationException ex) {
	// Always check if result file is present when an exception is thrown
	final AuthenticationFile file = authenticator.getResultFile();
	if (file != null) {
		// Save authentication file
		file.writeCompressed(outputStream);
	}
	
	// Show user error or rethrow
	throw ex;
}

// Save authentication file
final AuthenticationFile file = authenticator.getResultFile();
file.writeCompressed(outputStream);

// Get user
final Optional<User> user = authenticator.getUser();

Here is an login with an existing authentication file to refresh the session

// Build authenticator
final Authenticator authenticator = Authenticator.of(existingAuthFile).shouldAuthenticate().build();
try {
	// Run authentication
	authenticator.run();
} catch (final AuthenticationException ex) {
	// Always check if result file is present when an exception is thrown
	final AuthenticationFile file = authenticator.getResultFile();
	if (file != null) {
		// Save authentication file
		file.writeCompressed(outputStream);
	}
	
	// Show user error or rethrow
	throw ex;
}

// Save authentication file
final AuthenticationFile file = authenticator.getResultFile();
file.writeCompressed(outputStream);

// Get user
final Optional<User> user = authenticator.getUser();

Here is a login with a custom azure application and the retrieval of xbox profile settings

// Build authenticator
final Authenticator authenticator = Authenticator.ofMicrosoft(authorizationCode)
	.customAzureApplication(clientId, redirectUrl)
	.shouldRetrieveXBoxProfile()
	.shouldAuthenticate()
	.build();
try {
	// Run authentication
	authenticator.run();
} catch (final AuthenticationException ex) {
	// Always check if result file is present when an exception is thrown
	final AuthenticationFile file = authenticator.getResultFile();
	if (file != null) {
		// Save authentication file
		file.writeCompressed(outputStream);
	}
	
	// Show user error or rethrow
	throw ex;
}

// Save authentication file
final AuthenticationFile file = authenticator.getResultFile();
file.writeCompressed(outputStream);

// Get user
final Optional<User> user = authenticator.getUser();

// Get XBox profile
final Optional<XBoxProfile> xBoxProfile = authenticator.getXBoxProfile();

License

This project is licensed under apache 2 license. For more information see here.

minecraft-authenticator's People

Contributors

appledash avatar hycrafthd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.