TrademarkTrademark
Ctrl k
Search docs...
Sdk

Rust

Last update: August 25, 2025
Thumbnail of Rust
Crates.ioDocumentationLicense
Rust SDK for Go IAM API - Async/Await Support Add this to your Cargo.toml:
Toml
[dependencies]
goiam-rust = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
Rust
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:
Rust
#[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>;
}
Rust
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,
}
Rust
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),
}
On this page
© 2025 Go IAM. Open source under Apache 2.0 License.