SharePoint Integration
LibreChat provides enterprise-grade integration with SharePoint Online and OneDrive for Business, enabling users to seamlessly browse, select, and attach files from their Microsoft 365 environment directly within conversations.
Overview
The SharePoint integration allows users to:
- Browse SharePoint document libraries and OneDrive files
- Select multiple files at once (up to 10 by default)
- View real-time download progress
- Attach files from SharePoint to conversations
- Maintain enterprise security with proper access controls
Prerequisites
Before configuring SharePoint integration, ensure you have:
- Azure Entra ID Authentication configured and working
- Token Reuse enabled (
OPENID_REUSE_TOKENS=true
) - Admin access to your Azure tenant for app permissions
- HTTPS enabled (required for production environments)
Azure App Registration Setup
Step 1: Configure API Permissions
- Navigate to your app registration in the Azure Portal
- Go to API permissions in the left menu
- Click Add a permission
Step 2: Add SharePoint Permissions
For the file picker interface:
- Select SharePoint from the API list
- Choose Delegated permissions
- Search for and select:
AllSites.Read
- Read items in all site collections
- Click Add permissions
Step 3: Add Microsoft Graph Permissions
For file downloads:
- Click Add a permission again
- Select Microsoft Graph
- Choose Delegated permissions
- Search for and select:
Files.Read.All
- Read all files that user can access
- Click Add permissions
Step 4: Grant Admin Consent
- After adding both permissions, you’ll see them listed
- Click Grant admin consent for [Your Organization]
- Confirm the consent in the popup
Your permissions should look like this:
API / Permissions name | Type | Description | Status |
---|---|---|---|
Microsoft Graph - Files.Read.All | Delegated | Read all files that user can access | ✅ Granted |
SharePoint - AllSites.Read | Delegated | Read items in all site collections | ✅ Granted |
Environment Configuration
Add the following environment variables to your .env
file:
# Enable SharePoint file picker
ENABLE_SHAREPOINT_FILEPICKER=true
# Your SharePoint tenant base URL
# Format: https://[your-tenant-name].sharepoint.com
SHAREPOINT_BASE_URL=https://contoso.sharepoint.com
# SharePoint scope for the file picker
# Replace 'contoso' with your actual tenant name
SHAREPOINT_PICKER_SHAREPOINT_SCOPE=https://contoso.sharepoint.com/AllSites.Read
# Microsoft Graph scope for file downloads
SHAREPOINT_PICKER_GRAPH_SCOPE=Files.Read.All
How It Works
Authentication Flow
- User authenticates via Azure Entra ID
- When accessing SharePoint picker, LibreChat exchanges the user’s token for SharePoint access
- Tokens are cached for optimal performance (typically 50 minutes)
- Separate scopes ensure principle of least privilege
File Selection Process
- User clicks “From SharePoint” in the attachment menu
- SharePoint Online file picker opens in an embedded iframe
- User browses and selects files using familiar SharePoint interface
- Selected files are queued for download
Download Process
- Files are downloaded in batches (up to 3 concurrent downloads)
- Progress indicator shows current file and percentage complete
- Downloaded files are attached to the conversation
- Failed downloads are retried automatically
User Experience
Accessing SharePoint Files
When properly configured, users will see a new option in the file attachment menu:
- Click the attachment icon in the message input
- Select “From SharePoint” from the menu
- The SharePoint file picker will open
- Browse and select files as needed
- Click “Select” to begin downloading
Features Available
- Multiple file selection: Select up to 10 files at once
- Familiar interface: Uses native SharePoint file picker
- Progress tracking: See real-time download progress
- Error handling: Clear messages for any issues
- Localization: Supports multiple languages
Security Considerations
Access Control
- Only files the user has permission to access in SharePoint are available
- Respects all SharePoint permissions and policies
- No elevated access or bypassing of security controls
Token Security
- Uses secure on-behalf-of flow for token exchange
- Tokens are short-lived and automatically refreshed
- No long-term storage of SharePoint credentials
Scope Isolation
- SharePoint scope limited to read operations only
- Graph API scope restricted to file read access
- Cannot modify or delete files through LibreChat
Troubleshooting
Common Issues
”From SharePoint” option not appearing
Cause: Feature not properly enabled or authentication issues
Solutions:
- Verify
ENABLE_SHAREPOINT_FILEPICKER=true
in.env
- Confirm
OPENID_REUSE_TOKENS=true
is set - Check that user is authenticated via Azure Entra ID
- Restart LibreChat after configuration changes
File picker fails to open
Cause: Missing or incorrect permissions
Solutions:
- Verify SharePoint permissions are granted in Azure
- Ensure admin consent was provided
- Check that
SHAREPOINT_BASE_URL
matches your tenant exactly - Confirm HTTPS is enabled in production
Downloads fail or timeout
Cause: Graph API permissions or network issues
Solutions:
- Verify
Files.Read.All
permission is granted - Check network connectivity to SharePoint
- Ensure tokens haven’t expired (re-authenticate if needed)
- Check browser console for specific error messages
Debug Mode
For troubleshooting, enable debug logging:
DEBUG_LOGGING=true
DEBUG_CONSOLE=true
This will provide detailed logs about:
- Token exchange processes
- API calls to SharePoint and Graph
- Download progress and errors
- Authentication flows
Performance Optimization
Token Caching
- Tokens are cached to reduce authentication overhead
- Cache duration matches token lifetime (typically 50 minutes)
- Automatic refresh before expiration
Concurrent Downloads
- Up to 3 files download simultaneously
- Prevents overwhelming the browser or server
- Optimizes for both speed and stability
File Size Considerations
- Large files may take time to download
- Progress indicator helps manage user expectations
- Consider your file upload limits in LibreChat configuration
Best Practices
For Administrators
- Regular Permission Audits: Review app permissions periodically
- Monitor Usage: Track SharePoint integration usage in logs
- Update Documentation: Keep internal docs updated with your tenant specifics
- Test Thoroughly: Verify functionality after any Azure AD changes
For End Users
- File Organization: Well-organized SharePoint libraries improve user experience
- File Sizes: Be mindful of large files that may slow conversations
- Permissions: Ensure you have access to files before sharing
- Patient Downloads: Allow time for multiple or large files
Advanced Configuration
Custom Scopes
For organizations with specific requirements, you can customize scopes:
# Example: Limiting to specific site collections
SHAREPOINT_PICKER_SHAREPOINT_SCOPE=https://contoso.sharepoint.com/sites/Engineering/AllSites.Read
# Example: Using more restrictive Graph permissions
SHAREPOINT_PICKER_GRAPH_SCOPE=Files.Read
Integration with Information Barriers
If your organization uses Information Barriers:
- SharePoint integration respects all barrier policies
- Users only see content they’re allowed to access
- No additional configuration required