1 unstable release
0.1.0 | Sep 11, 2024 |
---|
#584 in Authentication
26KB
356 lines
Yggdrasil Authenticator Library
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
Features
- 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.
Sample Code
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(())
}
Dependencies
~5–16MB
~204K SLoC