• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

HyCraftHD/Minecraft-Authenticator: This is a library to authenticate a mojang an ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

HyCraftHD/Minecraft-Authenticator

开源软件地址(OpenSource Url):

https://github.com/HyCraftHD/Minecraft-Authenticator

开源编程语言(OpenSource Language):

Java 100.0%

开源软件介绍(OpenSource 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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
lilypuree/UnEarthed: Geologic Minecraft Mod发布时间:2022-08-17
下一篇:
Soartex-Modded/Modded-1.7.x: Soartex Mod Textures for Minecraft 1.7.x!发布时间:2022-08-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap