onairos
Version:
The Onairos Library is a collection of functions that enable Applications to connect and communicate data with Onairos Identities via User Authorization. Integration for developers is seamless, simple and effective for all applications. LLM SDK capabiliti
128 lines (102 loc) ⢠4.7 kB
Markdown
# Web Onairos SDK Integration
This folder contains the enhanced authentication flows and routes for the new web Onairos SDK integration.
## š Features
- **Unified Authentication**: Supports both API keys and user JWT tokens
- **Enhanced YouTube Integration**: Native mobile app support with proper refresh token handling
- **Dual Database Support**: Works with both Enoch and Onairos databases
- **Connection Health Monitoring**: Comprehensive status checking and validation
- **Auto Token Refresh**: Automatic token renewal using refresh tokens
- **Developer-Friendly**: Rate limiting per developer account with detailed error messages
## š Folder Structure
```
src/sdk-integration/
āāā middleware/
ā āāā unifiedApiKeyAuth.js # Unified API key authentication
ā āāā youtubeAuth.js # Smart YouTube authentication middleware
ā āāā rateLimiting.js # Rate limiting middleware
āāā routes/
ā āāā youtube-enhanced.js # Enhanced YouTube routes
ā āāā linkedin-enhanced.js # Enhanced LinkedIn routes
ā āāā validation.js # Connection validation endpoints
āāā utils/
ā āāā tokenManager.js # Token management utilities
ā āāā connectionHealth.js # Connection health checking
ā āāā databaseUtils.js # Database interaction utilities
āāā config/
ā āāā oauth-config.js # OAuth configuration
ā āāā sdk-config.js # SDK-specific configuration
āāā types/
ā āāā auth-types.js # Authentication type definitions
āāā docs/
āāā API_REFERENCE.md # Complete API reference
āāā AUTHENTICATION_GUIDE.md # Authentication guide
āāā INTEGRATION_EXAMPLES.md # Integration examples
```
## š§ Quick Setup
1. **Install Dependencies**: All existing dependencies are supported
2. **Environment Variables**: Use existing `.env` configuration
3. **Import Routes**: Replace existing routes with enhanced versions
4. **Update Frontend**: Use new authentication patterns
## š Authentication Patterns
### Pattern 1: API Key + User JWT (Recommended)
```javascript
// Headers
{
"x-api-key": "ona_your_api_key",
"authorization": "Bearer user_jwt_token"
}
```
### Pattern 2: User JWT Only (Enoch Users)
```javascript
// Headers
{
"authorization": "Bearer enoch_user_jwt_token"
}
```
### Pattern 3: API Key + User Context in Body
```javascript
// Headers
{
"x-api-key": "ona_your_api_key"
}
// Body
{
"authToken": "user_jwt_token",
"userAccountInfo": { ... }
}
```
## š Key Enhancements
1. **Smart Authentication**: Automatically detects user type and authentication method
2. **Comprehensive Error Handling**: Detailed error messages with specific guidance
3. **Connection Validation**: Real-time connection health checking
4. **Token Management**: Automatic refresh token handling
5. **Database Flexibility**: Supports both Enoch and Onairos databases
6. **Developer Tools**: Enhanced debugging and monitoring capabilities
## š Usage
Replace your existing route imports with the enhanced versions:
```javascript
// OLD
import youtubeRoutes from './routes/youtube.js';
// NEW
import youtubeRoutes from './sdk-integration/routes/youtube-enhanced.js';
```
## š Connection Health Monitoring
The SDK includes comprehensive connection health monitoring:
- **Real-time Validation**: Live API testing for each connection
- **Token Expiry Tracking**: Automatic detection of expired tokens
- **Refresh Token Management**: Automatic token renewal
- **Migration Detection**: Identifies users needing authentication upgrades
## š Documentation
- [API Reference](./docs/API_REFERENCE.md) - Complete endpoint documentation
- [Authentication Guide](./docs/AUTHENTICATION_GUIDE.md) - Authentication implementation guide
- [Integration Examples](./docs/INTEGRATION_EXAMPLES.md) - Frontend integration examples
## šØ Important Notes
1. **Refresh Tokens**: Ensure frontend includes refresh tokens for uninterrupted service
2. **Rate Limiting**: API key-based rate limiting per developer account
3. **Database Compatibility**: Dual storage for Enoch users ensures full compatibility
4. **Error Handling**: All endpoints provide detailed error information and next steps
## š¤ Support
For questions or issues:
1. Check the documentation in the `docs/` folder
2. Review error messages for specific guidance
3. Use the validation endpoints to diagnose connection issues