This Rust library provides an interface for interacting with Yggdrasil's authentication system. It includes models for handling authentication requests, responses, and errors, as well as a client for sending HTTP requests to authenticate, refresh, validate, and sign out users.
Implemented Standard: authlib-injector
- AuthClient: The main client for handling authentication operations.
- JSON Models: Structs for serializing/deserializing request and response data, including agents, profiles, users, and errors.
- Error Handling: Custom error types for handling authentication failures.
Add the library to your Cargo.toml
:
[dependencies]
yggdrasil-authenticator = "0.1.0"
use yggdrasil_authenticator::auth_agent::AuthAgent;
use yggdrasil_authenticator::client::client::AuthClient;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = AuthClient::new(
"https://myauthserver.com/auth-endpoint".to_string(), // No "/" at the end
None, // No proxy URL
);
// Authenticate a user
let agent = AuthAgent::new("Minecraft".to_string(), 1);
let auth_response = client
.authenticate(agent, "username", "password", "client_token", true)
.await?;
println!("Access Token: {}", auth_response.access_token);
// Refresh token
let refresh_response = client
.refresh(&auth_response.access_token, &auth_response.client_token, true, None)
.await?;
println!("New Access Token: {}", refresh_response.access_token);
Ok(())
}