All Projects → chris54721 → OpenMCAuthenticator

chris54721 / OpenMCAuthenticator

Licence: MIT license
A simple Java API for Minecraft authentication

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to OpenMCAuthenticator

netease-music-box
🎧 将你最近一周的网易云音乐的听歌记录更新到 Gist
Stars: ✭ 57 (+147.83%)
Mutual labels:  profile
proxifier-rules
Rules for proxifiers programs: Proxifier
Stars: ✭ 51 (+121.74%)
Mutual labels:  profile
geek-profile
👻 Geek Profile Maker based on Markdown
Stars: ✭ 85 (+269.57%)
Mutual labels:  profile
BlackIQ
Who I am !?
Stars: ✭ 19 (-17.39%)
Mutual labels:  profile
test-data-generation
Test Data Generation
Stars: ✭ 35 (+52.17%)
Mutual labels:  profile
github-pinner
📌 Pin and embed github repositories or profiles on your own website easily
Stars: ✭ 62 (+169.57%)
Mutual labels:  profile
open-source-enthusiasts
[ PLEASE DON'T USE THIS REPO ] Hacktoberfest 2020 movement to list out all the open source enthusiasts in one place. Want to make your PR count for Hacktoberfest? Add yourself in the list.
Stars: ✭ 40 (+73.91%)
Mutual labels:  profile
mojang
A wrapper for the Mojang API and Minecraft website
Stars: ✭ 19 (-17.39%)
Mutual labels:  mojang
SudhanPlayz
About me for GitHub <3
Stars: ✭ 24 (+4.35%)
Mutual labels:  profile
tinfoil
A minimalist tool to manage multiple profiles for web browsers
Stars: ✭ 20 (-13.04%)
Mutual labels:  profile
awesome-tasker
Carefully curated list of awesome Tasker projects, tutorials and tricks
Stars: ✭ 78 (+239.13%)
Mutual labels:  profile
itgoyo
a beautiful template make your github profile look awesome ,give me a star , plz orz
Stars: ✭ 104 (+352.17%)
Mutual labels:  profile
self
🦉 Cryptgraphic peer authentication.
Stars: ✭ 42 (+82.61%)
Mutual labels:  profile
notfilippo
✨ uwa, special ✨
Stars: ✭ 22 (-4.35%)
Mutual labels:  profile
DrakeAxelrod
Profile Page github repository
Stars: ✭ 30 (+30.43%)
Mutual labels:  profile
chrly
Lightweight implementation of Minecraft skins system server. It's packaged and distributed as a Docker image.
Stars: ✭ 23 (+0%)
Mutual labels:  mojang
nitter scraper
Scrape Twitter API without authentication using Nitter.
Stars: ✭ 31 (+34.78%)
Mutual labels:  profile
wc4bp
WooCommerce BuddyPress Integration
Stars: ✭ 18 (-21.74%)
Mutual labels:  profile
DenverCoder1
Jonah Lawrence's Profile README
Stars: ✭ 320 (+1291.3%)
Mutual labels:  profile
steam-box
🎮 Update profile README / pinned gist to contain your Steam playtime leaderboard. 在你的 profile README / pinned gist 上显示你的 steam 游玩时间排行榜。
Stars: ✭ 118 (+413.04%)
Mutual labels:  profile

OpenMCAuthenticator

Release

A simple, open and documented Java API for Minecraft authentication.

Features

  • Works with both Mojang and old Minecraft accounts
  • Provides methods for every endpoint
  • Custom exceptions for error reporting

Installation

Just add this to your build.gradle:

repositories {
  jcenter()
  maven { url "https://jitpack.io" }
}

dependencies {
  compile 'com.github.chris54721:openmcauthenticator:1.3.1'
}

Usage

The library uses mainly static methods. You won't have to instantiate anything. Just call the static methods in the class OpenMCAuthenticator with the required arguments to get your response.

The available methods are: authenticate, refresh, signout, validate and invalidate.

authenticate and refresh return a response object extending LoginResponse (AuthenticationResponse or RefreshResponse). This means, regardless of the method used, you will be able to use the following methods:

  • getAccessToken - returns the access token to be used when launching the game
  • getClientToken - returns the client token used in the request
  • getSelectedProfile - returns a Profile object representing the current profile

For a more detailed documentation, just check the javadoc included with the library.

Profiles

The Profile object is returned by loginResponse.getSelectedProfile() and a Profile[] object is returned by authenticationResponse.getAvailableProfiles() (where loginResponse and authenticationResponse are instances of the two classes). It contains the following (non-static) methods:

  • getUUID() - returns the user's UUID. Can be converted to a string with toString()
  • getName() - returns the nickname of the user with correct capitalization as a String
  • isLegacy() - returns a boolean; true if the profile is a legacy (old) Minecraft account (uses username to log in)

Exceptions

Every available method throws an exception extending RequestException if the request returned an authentication problem. The full list of exceptions is available below.

  • RequestException - a general exception. Every other authentication exception extends this. To get more detailed info about the exception, call getError() or getErrorMessage().
  • InvalidCredentialsException - the provided credentials are invalid (bad or empty username/password). Thrown by authenticate and signout.
  • InvalidTokenException - the provided token is invalid. Thrown by refresh, validate and invalidate.
  • UserMigratedException - the Mojang account email address should be used as the username instead of the nickname. Thrown by authenticate and signout.
  • AuthenticationUnavailableException - thrown every time an IOException is generated, so every time the authentication services are unavailable. Does not extend RequestException as there's no error code.

Exceptions example

try {
  // make request
} catch (RequestException e) {
  if (e instanceof AuthenticationUnavailableException) {
    // Authentication servers unavailable
  }
  if (e instanceof InvalidCredentialsException) {
    // Bad username or password
  }
}

Authentication

Use OpenMCAuthenticator.authenticate to request authentication with an username and a password.

try {
  AuthenticationResponse authResponse = OpenMCAuthenticator.authenticate("username", "password");
  String authToken = authResponse.getAccessToken();
} catch (RequestException e) {
  // handle exception
}

Refresh

Use OpenMCAuthenticator.refresh to request a new token by providing a valid one and the client token used to get the token in the first place. The token has to be the same to the one returned when getting the access token! See the Client tokens section for more info.

try {
  RefreshResponse refreshResponse = OpenMCAuthenticator.refresh("old accessToken", "used clientToken");
  String authToken = refreshResponse.getAccessToken();
} catch (RequestException e) {
  // handle exception
}

Validate

Use OpenMCAuthenticator.validate to check if the provided access token represents the latest active session. This will return true only if the token is the most recently generated. It's intended to be used by servers to check if the player is not logged in elsewhere with a new access token.

try {
  boolean isValid = OpenMCAuthenticator.validate("accessToken");
} catch (RequestException e) {
  // handle exception
}

Invalidate

Use OpenMCAuthenticator.invalidate to invalidate the given access token. The client token has to be the same to the one returned when getting the access token! See the Client tokens section for more info.

try {
  boolean success = OpenMCAuthenticator.invalidate("accessToken", "clientToken");
} catch (RequestException e) {
  // handle exception
}

Signout

Use OpenMCAuthenticator.signout to invalidate every access token for an user by providing its username and password.

try {
  boolean success = OpenMCAuthenticator.signout("username", "password");
} catch (RequestException e) {
  // handle exception
}

Client tokens

The clientToken value is intended to be generated randomly for authenticate, signout and validate (while request and invalidate require it to be the same to the one received when getting the token)

OpenMCAuthenticator by default doesn't send a client token when optional, as the authentication servers automatically generate one (by default a random UUID, which is then obtainable by the client by calling getClientToken() on the returned LoginResponse). If for some reason you need to use a custom client token, just add it as a String to the request method parameters. For example:

// Default (the server will generate the token)
OpenMCAuthenticator.authenticate("username", "password");

// Send a new random UUID generated by the client as the token
OpenMCAuthenticator.authenticate("username", "password", UUID.randomUUID().toString());

// Send a randomly generated secure session identifier (random 32-chars string)
String token = new BigInteger(130, new SecureRandom()).toString(32);
OpenMCAuthenticator.authenticate("username", "password", token);

Reporting issues

If you found an issue in the API, just click here to report it! Try to be as accurate as possible and add some steps to reproduce the issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].