| Crates.io | vortex-sdk |
| lib.rs | vortex-sdk |
| version | 1.1.3 |
| created_at | 2025-10-20 22:51:46.529332+00 |
| updated_at | 2026-01-05 23:56:12.586565+00 |
| description | Vortex Rust SDK for authentication and invitation management |
| homepage | https://vortexsoftware.com |
| repository | https://github.com/teamvortexsoftware/vortex |
| max_upload_size | |
| id | 1892854 |
| size | 128,081 |
This crate provides the Vortex Rust SDK for authentication and invitation management.
With this SDK, you can generate JWTs for use with the Vortex Widget and make API calls to the Vortex API.
Add the SDK to your Cargo.toml:
[dependencies]
vortex-sdk = "1.0"
tokio = { version = "1.0", features = ["full"] }
Once you have the SDK installed, login to Vortex and create an API Key. Keep your API key safe! Vortex does not store the API key and it is not retrievable once it has been created.
Your API key is used to:
The Vortex Widget requires a JWT to authenticate users. Here's how to generate one:
use vortex_sdk::{VortexClient, User};
fn main() {
// Initialize the Vortex client with your API key
let client = VortexClient::new(std::env::var("VORTEX_API_KEY").unwrap());
// Create a user and generate JWT
let user = User::new("user-123", "user@example.com")
.with_admin_scopes(vec!["autojoin".to_string()]);
let jwt = client.generate_jwt(&user, None).unwrap();
println!("JWT: {}", jwt);
}
You can include additional properties in the JWT payload:
use vortex_sdk::{VortexClient, User};
use std::collections::HashMap;
fn main() {
let client = VortexClient::new(std::env::var("VORTEX_API_KEY").unwrap());
let user = User::new("user-123", "user@example.com");
let mut extra = HashMap::new();
extra.insert("role".to_string(), serde_json::json!("admin"));
extra.insert("department".to_string(), serde_json::json!("Engineering"));
let jwt = client.generate_jwt(&user, Some(extra)).unwrap();
println!("JWT: {}", jwt);
}
All API methods are async and require a tokio runtime:
use vortex_sdk::{VortexClient, User};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = VortexClient::new(std::env::var("VORTEX_API_KEY")?);
// Generate a JWT
let user = User::new("user-123", "user@example.com")
.with_admin_scopes(vec!["autojoin".to_string()]);
let jwt = client.generate_jwt(&user, None)?;
println!("JWT: {}", jwt);
// Get invitations by target
let invitations = client
.get_invitations_by_target("email", "user@example.com")
.await?;
println!("Found {} invitations", invitations.len());
Ok(())
}
Here's an example of using the SDK with the Axum web framework:
use axum::{
extract::State,
http::StatusCode,
response::Json,
routing::get,
Router,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use vortex_sdk::VortexClient;
#[derive(Clone)]
struct AppState {
vortex: Arc<VortexClient>,
}
#[derive(Serialize)]
struct JwtResponse {
jwt: String,
}
async fn get_jwt(State(state): State<AppState>) -> Result<Json<JwtResponse>, StatusCode> {
let user = vortex_sdk::User::new("user-123", "user@example.com");
let jwt = state
.vortex
.generate_jwt(&user, None)
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(Json(JwtResponse { jwt }))
}
#[tokio::main]
async fn main() {
let vortex = Arc::new(VortexClient::new(
std::env::var("VORTEX_API_KEY").unwrap(),
));
let app = Router::new()
.route("/api/vortex-jwt", get(get_jwt))
.with_state(AppState { vortex });
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
axum::serve(listener, app).await.unwrap();
}
All API methods are asynchronous and require the tokio runtime.
let invitations = client
.get_invitations_by_target("email", "user@example.com")
.await?;
let invitation = client.get_invitation("invitation-id").await?;
client.revoke_invitation("invitation-id").await?;
use vortex_sdk::InvitationTarget;
let target = InvitationTarget::new("email", "user@example.com");
let result = client
.accept_invitations(
vec!["invitation-id-1".to_string(), "invitation-id-2".to_string()],
target,
)
.await?;
let invitations = client
.get_invitations_by_group("workspace", "workspace-123")
.await?;
client
.delete_invitations_by_group("workspace", "workspace-123")
.await?;
let result = client.reinvite("invitation-id").await?;
The SDK uses a custom VortexError type for error handling:
use vortex_sdk::{VortexClient, VortexError};
match client.get_invitation("invalid-id").await {
Ok(invitation) => println!("Got invitation: {:?}", invitation),
Err(VortexError::ApiError(msg)) => eprintln!("API error: {}", msg),
Err(VortexError::HttpError(msg)) => eprintln!("HTTP error: {}", msg),
Err(e) => eprintln!("Other error: {}", e),
}
MIT
For support, please contact support@vortexsoftware.com or visit our documentation.