SharePoint Integration
Configure SharePoint Online and OneDrive for Business integration with LibreChat
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
Enterprise Feature
This feature requires Microsoft 365/SharePoint Online and is designed for enterprise deployments using Azure Entra ID (formerly Azure AD) authentication.
Prerequisites
Before configuring SharePoint integration, ensure you have:
- Azure Entra ID Authentication configured and working
- Token Reuse enabled (
OPENID_REUSE_TOKENS=true) - An exposed API scope for LibreChat, such as
api://<client-id>/access_as_user - Admin access to your Azure tenant for app permissions
- HTTPS enabled (required for production environments)
Critical Requirement
SharePoint integration will not function without OPENID_REUSE_TOKENS=true as it relies on the on-behalf-of token flow to access Microsoft Graph APIs.
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: Expose and Grant a LibreChat API Scope
The on-behalf-of flow needs the initial OpenID access token to target your LibreChat app API, not Microsoft Graph. Expose an API scope so Azure can issue a token with LibreChat as the audience.
- Go to Expose an API in the left menu
- Set the Application ID URI to
api://<client-id>if it is not already configured - Click Add a scope
- Name the scope
access_as_user - Save the scope, then copy the full scope value:
Then grant that scope to the app registration:
- Go back to API permissions
- Click Add a permission
- Select APIs my organization uses
- Search for and select your LibreChat app registration
- Choose Delegated permissions
- Select
access_as_user - Click Add permissions
Use the full api://<client-id>/access_as_user scope value in OPENID_SCOPE later in this guide.
Step 3: 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 4: 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 5: Grant Admin Consent
- After adding the 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 |
| LibreChat - access_as_user | Delegated | Allow LibreChat to receive an OBO-compatible token | ✅ Granted |
Environment Configuration
Add the following environment variables to your .env file:
Tenant Name
Ensure you replace contoso in the examples above with your actual SharePoint tenant name. This must match your SharePoint URL exactly.
OpenID Scope Audience
Replace <client-id> with your Azure app registration's Application (client) ID. The api://<client-id>/access_as_user scope gives Azure an app-specific audience for the OBO assertion. If OPENID_SCOPE only includes standard OpenID scopes, Azure may issue a Graph-audience access token that cannot be exchanged again for SharePoint or Graph access.
Userinfo Token Exchange
OPENID_ON_BEHALF_FLOW_FOR_USERINFO_REQUIRED=true lets LibreChat exchange the app-audience access token for a userinfo-compatible token before calling the OpenID userinfo endpoint. This is required for Azure Entra ID setups where the OPENID_SCOPE includes the LibreChat API scope above.
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=truein.env - Confirm
OPENID_REUSE_TOKENS=trueis 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_URLmatches your tenant exactly - Confirm
SHAREPOINT_PICKER_SHAREPOINT_SCOPEuses the full tenant URL, such ashttps://contoso.sharepoint.com/AllSites.Read - Confirm HTTPS is enabled in production
File picker opens to a blank white page
Cause: Azure may be rejecting the on-behalf-of exchange because the OpenID access token has the wrong audience, or because the userinfo token exchange is not enabled.
Solutions:
- Confirm your Azure app registration has an exposed API scope, such as
api://<client-id>/access_as_user - Add that full scope to
OPENID_SCOPE - Set
OPENID_ON_BEHALF_FLOW_FOR_USERINFO_REQUIRED=true - Restart LibreChat and sign in again so Azure issues fresh OpenID tokens
Downloads fail or timeout
Cause: Graph API permissions or network issues
Solutions:
- Verify
Files.Read.Allpermission 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:
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:
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
Related Documentation
How is this guide?