Connect D3PA to Microsoft OneDrive for file access.
This guide covers:
- Creating an Azure AD app registration
- Configuring permissions for OneDrive
- Setting up authentication
- Testing the connection
Time needed: 20-30 minutes
You'll need:
- A Microsoft 365 account (university or work account)
- Access to Azure Portal (usually via your organization)
- Admin consent may be required for some permissions
- Open portal.azure.com
- Sign in with your Microsoft 365 account
- Search for App registrations and click it
- Click New registration
- Fill in details:
- Name:
D3PA OneDrive - Supported account types: "Accounts in this organizational directory only"
- Redirect URI: Select "Web" and enter
http://localhost:8000/callback
- Name:
- Click Register
After creation, you'll see:
- Application (client) ID: Copy this
- Directory (tenant) ID: Copy this
- Go to Certificates & secrets
- Click New client secret
- Enter description:
D3PA secret - Choose expiration (recommended: 12 months)
- Click Add
Important: Copy the Value immediately - it won't be shown again!
- Go to API permissions
- Click Add a permission
- Select Microsoft Graph
- Choose Delegated permissions
- Add these permissions:
| Permission | Purpose |
|---|---|
Files.Read |
Read user's files |
Files.Read.All |
Read all files user can access |
User.Read |
Read user profile |
Optional permissions:
| Permission | Purpose |
|---|---|
Files.ReadWrite |
Read and write files |
Sites.Read.All |
Read SharePoint sites |
If you see a warning about admin consent:
- Click Grant admin consent for [Your Organization]
- Click Yes to confirm
If you don't have admin rights, ask your IT administrator.
Add to your .env file:
MICROSOFT_CLIENT_ID=your-application-id
MICROSOFT_CLIENT_SECRET=your-secret-value
MICROSOFT_TENANT_ID=your-tenant-idThe first time you use OneDrive tools, you'll need to authenticate.
python -c "from src.integrations.onedrive_client import OneDriveClient; OneDriveClient().authenticate()"- A browser window will open
- Sign in with your Microsoft account
- Approve the permissions
- You'll be redirected to localhost
- The token will be saved automatically
from src.integrations.onedrive_client import OneDriveClient
client = OneDriveClient()
files = client.list_files()
print(files)Send a message to your bot:
- "List my OneDrive files"
- "Search for budget.xlsx in OneDrive"
The redirect URI doesn't match:
- Go to App registrations → Your app → Authentication
- Add or update the redirect URI to match your callback URL
- Save changes
Admin consent is needed:
- Ask your IT admin to grant consent
- Or go to API permissions → Grant admin consent
Token expired or invalid:
- Delete the cached token:
rm ~/.d3pa_token.json - Run authentication again
- Check that your client secret hasn't expired
- Check you have the right permissions configured
- Make sure admin consent was granted
- Verify the file/folder isn't restricted
For server-side access without user login:
- Go to API permissions
- Add permissions as Application permissions instead of Delegated
- Grant admin consent
| Permission | Purpose |
|---|---|
Files.Read.All |
Read all files in the organization |
Sites.Read.All |
Read all SharePoint sites |
from msal import ConfidentialClientApplication
app = ConfidentialClientApplication(
client_id=settings.microsoft_client_id,
client_credential=settings.microsoft_client_secret,
authority=f"https://login.microsoftonline.com/{settings.microsoft_tenant_id}"
)
result = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])
token = result["access_token"]GET /me/drive/root/childrenGET /me/drive/root/search(q='{query}')GET /me/drive/items/{item-id}/contentGET /me/drive/items/{item-id}After setup, these tools are available:
| Tool | Description |
|---|---|
search_onedrive |
Search files by name or content |
list_onedrive_folder |
List files in a folder |
read_onedrive_file |
Read file contents |
- Never commit secrets - Keep
.envout of git - Rotate secrets - Update client secret before expiration
- Minimal permissions - Only request what you need
- Token storage - Tokens are stored locally, keep them secure
With OneDrive connected:
- Try the file tools: "Search for meeting notes"
- Build custom tools using the OneDrive client
- See Building Tools for examples