| Crates.io | goiam |
| lib.rs | goiam |
| version | 0.3.0 |
| created_at | 2025-08-13 04:15:31.2226+00 |
| updated_at | 2025-09-11 18:55:56.485869+00 |
| description | Rust SDK for Go IAM - A lightweight Identity and Access Management server |
| homepage | https://github.com/melvinodsa/go-iam-sdk |
| repository | https://github.com/melvinodsa/go-iam-sdk |
| max_upload_size | |
| id | 1793249 |
| size | 86,946 |
Rust SDK for Go IAM API - Async/Await Support
Add this to your Cargo.toml:
[dependencies]
goiam-rust = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
use goiam_rust::{new_service, Service, Resource};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the service
let service = new_service(
"https://api.goiam.com".to_string(),
"your-client-id".to_string(),
"your-secret".to_string()
);
// Verify a code and get access token
match service.verify("authorization-code").await {
Ok(token) => {
println!("Access Token: {}", token);
// Get user information
let user = service.me(&token).await?;
println!("User: {} ({})", user.name, user.email);
// Create a resource
let resource = Resource::new("resource-1".to_string(), "My Resource".to_string());
service.create_resource(&resource, &token).await?;
println!("Resource created successfully");
},
Err(e) => eprintln!("Verification failed: {}", e),
}
Ok(())
}
The main interface for interacting with Go IAM API:
#[async_trait]
pub trait Service: Send + Sync {
async fn verify(&self, code: &str) -> Result<String, GoIamError>;
async fn me(&self, token: &str) -> Result<User, GoIamError>;
async fn create_resource(&self, resource: &Resource, token: &str) -> Result<(), GoIamError>;
}
pub struct User {
pub id: String,
pub project_id: String,
pub name: String,
pub email: String,
pub phone: String,
pub enabled: bool,
pub profile_pic: String,
pub expiry: Option<String>,
pub roles: HashMap<String, serde_json::Value>,
pub resources: HashMap<String, serde_json::Value>,
pub policies: HashMap<String, serde_json::Value>,
pub created_at: Option<String>,
pub created_by: String,
pub updated_at: Option<String>,
pub updated_by: String,
}
pub struct Resource {
pub id: String,
pub name: String,
}
use goiam_rust::{GoIamError, Service};
match service.verify("code").await {
Ok(token) => println!("Success: {}", token),
Err(GoIamError::Http(status)) => eprintln!("HTTP error: {}", status),
Err(GoIamError::Request(e)) => eprintln!("Request error: {}", e),
Err(GoIamError::Parse(e)) => eprintln!("Parse error: {}", e),
Err(GoIamError::Api(msg)) => eprintln!("API error: {}", msg),
}
Run the tests with:
cargo test
Run tests with output:
cargo test -- --nocapture
This project is licensed under the MIT License.