atproto-oauth-aip
AT Protocol OAuth implementation for AT Protocol Identity Provider (AIP) integration. This crate provides high-level OAuth workflow functions for client applications that need to authenticate with AT Protocol services.
Overview
atproto-oauth-aip builds on top of the foundational atproto-oauth crate to provide a complete OAuth authentication workflow specifically tailored for AT Protocol. It handles the full OAuth flow including:
- OAuth metadata discovery
- Pushed Authorization Request (PAR) initiation
- Authorization code exchange
- AT Protocol session establishment
Features
- PAR Support: Enhanced security through Pushed Authorization Requests
- AT Protocol Session Exchange: Convert OAuth tokens to rich AT Protocol sessions
- DPoP Integration: Support for Demonstration of Proof-of-Possession tokens
- Comprehensive Error Handling: Typed errors for each OAuth operation
- Async/Await: Fully asynchronous implementation using Tokio
Installation
Add this to your Cargo.toml:
[]
= "0.9.5"
Usage
Basic OAuth Flow
use ;
use MemoryStorage;
async
Fetching OAuth Metadata
use ;
// Get OAuth protected resource configuration
let protected_resource = oauth_protected_resource.await?;
// Get OAuth authorization server metadata
let auth_server = oauth_authorization_server.await?;
API Documentation
Core Types
OAuthClient: OAuth client credentials and configurationATProtocolSession: Authenticated session containing DID, handle, and PDS endpoint
Main Functions
oauth_init(): Initiates OAuth flow using PARoauth_complete(): Exchanges authorization code for access tokensession_exchange(): Converts OAuth access token to AT Protocol session
Resource Functions
oauth_protected_resource(): Fetch OAuth protected resource metadataoauth_authorization_server(): Fetch OAuth authorization server metadata
Error Handling
The crate uses typed errors following the AT Protocol error format:
use OAuthWorkflowError;
match result
Storage Requirements
This crate requires an implementation of the OAuthStorage trait from atproto-oauth. For production use, implement persistent storage rather than using MemoryStorage.
Security Considerations
- Always use HTTPS URLs for OAuth endpoints
- Implement proper state validation to prevent CSRF attacks
- Store client secrets securely
- Use persistent storage with appropriate security measures
- Validate DPoP keys when required by the authorization server
Dependencies
This crate depends on:
atproto-oauth: Core OAuth implementationatproto-identity: AT Protocol identity resolutionatproto-record: Record handlingreqwest: HTTP clientserde: Serializationtokio: Async runtime
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.