atomic-lti
atomic-lti is a Rust library that provides support for integrating with the LTI 1.3 and LTI Advantage standards provided by 1EdTech.
Overview
This library provides core types, traits, and utilities for building LTI 1.3 compliant tools. It includes comprehensive store traits for managing platforms, registrations, OIDC state, keys, and JWTs.
Supported LTI Advantage Specifications
The following LTI Advantage specifications are supported:
- Names and Roles Provisioning Service (NRPS)
- Assignment and Grade Services (AGS)
- Deep Linking 2.0
Features
- Complete LTI 1.3 Core support
- Enhanced store traits with CRUD operations
- Platform and registration management
- OIDC state tracking with issuer support
- JWT validation and signing
- Type-safe error handling
- Async/await throughout
Installation
To use atomic-lti in your Rust project, add the following to your Cargo.toml file:
[]
= "2.1.0"
Enhanced Store Traits
PlatformStore
The PlatformStore trait manages LMS platform configurations. It provides both legacy single-platform methods and modern CRUD operations for multi-platform scenarios.
Platform Data Structure
use PlatformData;
let platform = PlatformData ;
CRUD Operations
use PlatformStore;
// Create a new platform
let created = store.create.await?;
// Find by issuer
let found = store.find_by_iss.await?;
// Update platform
platform.name = Some;
let updated = store.update.await?;
// List all platforms
let all_platforms = store.list.await?;
// Delete platform
store.delete.await?;
Backward Compatible Methods
For single-platform scenarios, legacy methods are still supported:
let oidc_url = store.get_oidc_url.await?;
let jwks_url = store.get_jwk_server_url.await?;
let token_url = store.get_token_url.await?;
Implementation Example
use ;
use PlatformError;
use async_trait;
RegistrationStore
The RegistrationStore trait manages LTI tool registrations, including OAuth2 credentials, deployment information, and tool capabilities.
Registration Data Structure
use RegistrationData;
use json;
let registration = RegistrationData ;
Helper Methods
// Check if registration supports a placement
if registration.supports_placement
// Check if registration supports a message type
if registration.supports_message_type
// Get a specific capability
if let Some = registration.get_capability
Store Operations
use RegistrationStore;
// Create a new registration
let created = store.create.await?;
// Find by client ID
let found = store.find_by_client_id.await?;
// Find by platform and client ID (useful for multi-tenant scenarios)
let found = store.find_by_platform_and_client.await?;
// Update status
let updated = store.update_status.await?;
// Update capabilities
let new_capabilities = json!;
let updated = store.update_capabilities.await?;
OIDCStateStore
The OIDCStateStore trait manages OIDC authentication state and nonce values. Enhanced with issuer tracking for multi-platform support.
use OIDCStateStore;
// Get state and nonce
let state = store.get_state.await;
let nonce = store.get_nonce.await;
// Get issuer (enhanced feature)
if let Some = store.get_issuer.await
// Check creation time
let created_at = store.get_created_at.await;
// Destroy state after use
store.destroy.await?;
The issuer field allows associating OIDC state with specific platforms, enabling proper state validation in multi-platform scenarios.
KeyStore
The KeyStore trait manages RSA key pairs for JWT signing and verification.
use KeyStore;
// Get current key for signing
let = store.get_current_key.await?;
// Get multiple keys (for key rotation)
let keys = store.get_current_keys.await?;
// Get specific key by ID
let key = store.get_key.await?;
JwtStore
The JwtStore trait handles JWT creation from LTI ID tokens.
use JwtStore;
// Build JWT from ID token
let jwt = store.build_jwt.await?;
JWT Utilities
The library provides utilities for encoding and decoding JWTs with automatic key management:
use ;
use ;
// Encode claims to JWT
let claims = MyClaims ;
let jwt_string = encode_using_store.await?;
// Decode JWT back to claims
let token_data = .await?;
println!;
Error Handling
The library provides comprehensive error types:
use *;
// Platform errors
InvalidIss
NotFound
// Registration errors
NotFound
AlreadyExists
// OIDC errors
InvalidState
ExpiredState
// Security errors
InvalidKeyId
EmptyKeys
JwtError
Migration from Previous Versions
PlatformStore Changes
Before (single platform):
async ;
After (multi-platform):
// Legacy method still works
async ;
// New CRUD methods
async ;
async ;
async ;
async ;
async ;
OIDCStateStore Changes
Enhanced with issuer tracking:
// New method
async ;
All existing methods remain backward compatible.
New RegistrationStore
The RegistrationStore trait is entirely new and provides registration management capabilities.
Best Practices
1. Multi-Platform Support
When supporting multiple LMS platforms, use the enhanced CRUD methods:
// List all configured platforms
let platforms = platform_store.list.await?;
for platform in platforms
2. Registration Management
Store registration data with all relevant fields for proper tool configuration:
let registration = RegistrationData ;
registration_store.create.await?;
3. State Cleanup
Always clean up OIDC states after use to prevent database bloat:
async
4. Error Handling
Use pattern matching for comprehensive error handling:
match platform_store.find_by_iss.await
Testing
The library includes comprehensive tests for all store traits:
For testing your implementations, use the in-memory test stores provided in the test modules, or create mock implementations.
Examples
See the following projects for complete implementations:
- atomic-decay - SQLx-based implementation with PostgreSQL
- atomic-oxide - Diesel-based implementation with PostgreSQL
Related Crates
- atomic-lti-tool - Tool-specific structures and dependency injection
- atomic-lti-tool-axum - Axum web framework integration
- atomic-lti-test - Testing utilities and mock implementations
Run Tests
To run the tests for atomic-lti, use the following command:
License
MIT