This is a simple authentication API for the xbox authentication system. The API uses the OAuth2 protocol to authenticate users by microsoft.
This API supports the minecraft authentication service and the responses.
First you need a OAuth2.0 client ID.
See here to create a ID.
Then follow the docs here to
get an access token.
With the following code you can authenticate a user with your access token and login to the XboxLive account.
The LoginInToXboxLiveResponse
contains several information and the final token. The relyingParty is the application where to authorize the user. For example is the application url from minecraft: rp://api.minecraftservices.com/
.
try {
LoginInToXboxLiveResponse authenticateResponse = AuthenticationAPI.authenticate("<your access token>", "<relyingParty>");
} catch (Exception e) {
throw new RuntimeException(e);
}
With the following code can you authorize with the minecraft api. You get information like the bearer token or the players name. The bearer token is useful authorize with the minecraft api website to get more information about the minecraft account.
See here for the list of the features of the minecraft web api.
try {
MinecraftProfileResponse profileResponse = HTTPUtils.authenticateWithToken("https://api.minecraftservices.com/minecraft/profile", authenticateResponse.accessToken, MinecraftProfileResponse.class);
String token = profileResponse.name;
} catch(Exception e) {
throw new RuntimeException(e);
}
You can use more features from the minecraft web api. See here for the features that are all implemented in my api. You can see the currently implemented features in this package. Look in the documentations for getting other information about the player.
This example shows how to get the xbox live account username of the player and check if the player has enabled to use the minecraft chat in the xbox live settings.
Use the MinecraftAuthAPI class to get even simpler information about the Minecraft account.
public class TestClass {
public static void main(String[] args) throws Exception {
String accessToken = "<your accessToken>"; //See in the #How to use step how to get the accessToken
LoginInToXboxLiveResponse authenticateResponse = AuthenticationAPI.authenticateWithMinecraft(accessToken); //This method authorize with the xboxlive account with the minecraft RelyingParty url
MinecraftProfileResponse profileResponse = HTTPUtils.authenticateWithToken("https://api.minecraftservices.com/minecraft/profile", authenticateResponse.accessToken, MinecraftProfileResponse.class);
System.out.println("Profile Name of the Minecraft account user: " + profileResponse.name);
//Next we getting the information if the xbox account has enabled that the onlinechat gets showed to the player.
//I used the documention here https://wiki.vg/Mojang_API#Player_Attributes
MinecraftPlayerAttributesResponse playerAttributesResponse = HTTPUtils.authenticateWithToken("https://api.minecraftservices.com/player/attributes", authenticateResponse.accessToken, new MinecraftPlayerAttributesResponse.MinecraftPlayerAttributesRequest(false), MinecraftPlayerAttributesResponse.class);
System.out.println("The setting if the player has the online chat enabled in minecraft: " + playerAttributesResponse.privileges.onlineChat.enabled);
}
}
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<dependency>
<groupId>com.github.ZeusSeinGrossopa</groupId>
<artifactId>Authentication-API</artifactId>
<version>1.1.0</version>
</dependency>
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.ZeusSeinGrossopa:Authentication-API:1.0.0'
}
- mojang-api-docs
- https://wiki.vg/Microsoft_Authentication_Scheme
- https://wiki.vg/Mojang_API
- Microsoft OAuth 2.0 Docs
- Wikipedia OAuth 2.0