https://github.com/noyzys/nautchkafe-auth-rest
Extensible rest api for authentication with Mojang and similar services.
https://github.com/noyzys/nautchkafe-auth-rest
authentication bukkit fp functional-programming java minecraft mojang mojang-api proxy ratelimit ratelimiter rest rest-api rust spigot spring-boot vavr velocity
Last synced: 8 months ago
JSON representation
Extensible rest api for authentication with Mojang and similar services.
- Host: GitHub
- URL: https://github.com/noyzys/nautchkafe-auth-rest
- Owner: noyzys
- Created: 2024-11-24T17:02:45.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-02-24T16:51:06.000Z (9 months ago)
- Last Synced: 2025-02-24T17:47:01.210Z (9 months ago)
- Topics: authentication, bukkit, fp, functional-programming, java, minecraft, mojang, mojang-api, proxy, ratelimit, ratelimiter, rest, rest-api, rust, spigot, spring-boot, vavr, velocity
- Language: Java
- Homepage:
- Size: 34.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Rust & Java Rest-Api
* library designed to handle rate limiting for authentication requests, specifically for Mojang and similar services.
## Features:
* Rate Limiting: Ensures requests are spaced by a defined interval to avoid exceeding rate limits.
* Request Queue (Rq): The RequestQueue class is responsible for managing a queue of HTTP requests to be processed sequentially.
* Asynchronous Design: Utilizes async/await syntax us execution, making it highly efficient for concurrent network requests.
* Backoff Mechanism: Implements a retry strategy with backoff duration when the rate limit is exceeded.
* Concurrency Safe: mutex to manage shared state across multiple async tasks, ensuring safe concurrent access to the rate limiter state.
* Validations
### Java use case:
```java
public static void main(String[] args) throws ExecutionException, InterruptedException {
AuthRestClient httpClient = new AuthRestClient(); // HTTP client to make requests
AuthRequestQueuePool requestQueue = new AuthRequestQueuePool(); // Request queue pool to manage request queuing
AuthRateLimiter rateLimiter = new AuthRateLimiter(5, Duration.ofSeconds(1)); // Rate limiter with a max of 5 requests per second
AuthValidator authValidator = new AuthValidator(httpClient, requestQueue, rateLimiter);
String username = "nautchkafe";
CompletableFuture> authenticationResult = authValidator.authenticate(username);
authenticationResult.thenAccept(result -> result.peek(authUserProfile -> {
System.out.println("Authentication successful!");
System.out.println("Username: " + authUserProfile.name());
System.out.println("UUID: " + authUserProfile.uuid());
}).peekLeft(error -> {
System.err.println("Authentication failed: " + error);
})).join();
}
```
### Rust use case:
```rust
async fn main() {
let http_client = AuthRestClient::new();
let rate_limiter = AuthMojangRateLimiter::new(5);
let auth_validator = AuthValidator::new(http_client, rate_limiter);
// Attempt authentication
match auth_validator.authenticate("sus".to_string()).await {
Ok(Either::Right(auth_user_profile)) => {
println!("Authentication successful!");
println!("Username: {}", auth_user_profile.username);
println!("UUID: {}", auth_user_profile.uuid);
}
}
```
```
sout logger:
Rate limited request for user: sus
Authenticated user: sus
UUID: 9d5f1a90-c4f9-412b-9d93-4d2a5f7a3f62
```
### Velocity proxy support
```java
// import com.velocitypowered.api.proxy.Player, import com.velocitypowered.api.proxy.ProxyServer
public CompletableFuture> authenticateWithRateLimit(Player player) {
String username = player.getUsername();
return isPremium(username).thenCompose(isPremium -> {
return Option.of(isPremium).filter(Boolean::booleanValue)
.map(_ -> {
System.out.println("User is premium, skipping rate limit for: " + username);
return authCoordinator.authenticate(username);
}).getOrElse(() -> {
return rateLimiter.executeWithRateLimit(() -> authCoordinator.authenticate(username));
});
});
}
//event
void onPlayerJoin(Player player) {
authenticateWithRateLimit(player).thenAccept(result -> result.peek(authUserProfile -> {
System.out.println("Authentication successful for: " + authUserProfile.getUsername());
}).peekLeft(error -> {
System.err.println("Authentication failed for: " + error);
}));
}
@Listener
public void onPlayerJoin(PlayerJoinEvent event) {
join(event.getPlayer());
}
```
**If you are interested in exploring functional programming and its applications within this project visit the repository at [vavr-in-action](https://github.com/noyzys/bukkit-vavr-in-action), [fp-practice](https://github.com/noyzys/fp-practice).**