Skip to content

nordeim/Microsoft_Onedrive_python_web

Repository files navigation

Microsoft Onedrive with python web ui

Setup Instructions:

  1. Create Azure AD Application:

    • Go to Azure Portal → App Registrations → New Registration
    • Set redirect URI to http://localhost:8000/callback
    • Add client secret and note down CLIENT_ID & CLIENT_SECRET
  2. Install requirements:

pip install gradio msal python-dotenv requests msgraph-sdk
  1. Create .env file:
CLIENT_ID=your_azure_client_id
CLIENT_SECRET=your_azure_client_secret

Features:

  • Modern Gradio interface with emoji icons
  • File/folder navigation with breadcrumbs
  • Upload/download functionality
  • Folder creation/delete operations
  • Responsive design with theme support
  • Secure token management
  • Real-time updates

Key Improvements and Integrations:

  1. Hybrid Architecture
  • Combines REST API direct calls (from reference code) with OOP wrapper class
  • Maintains SDK-like convenience while keeping transparency of API operations
  1. Enhanced Authentication Flow
  • Interactive authentication sequence with automatic token refresh
  • Secure state management instead of global variables
  • Complete OAuth 2.0 code flow with PKCE support
  1. Modern UI Features
  • Hybrid tabbed/navigation interface combining both approaches
  • Visual folder breadcrumbs
  • Interactive file tree with type icons
  • Multiple file upload support
  1. Improved Error Handling
  • Automatic token refresh on 401 errors
  • Detailed operation logging
  • Visual feedback for all actions
  1. Advanced Features
  • Full folder navigation history with stack
  • Type-safe API request handler
  • Multi-threaded upload capability
  • Responsive layout with collapsible panels
  1. Security Enhancements
  • Secure token storage in session state
  • Environment variable configuration
  • No persistent credential storage
  1. Extended Operations
  • Drag-and-drop file upload
  • Batch operations
  • Contextual navigation
  • Detailed metadata display

To use this improved version:

  1. Install requirements:
pip install gradio requests msal python-dotenv
python onedrive_gradio_r1-v2.py
  1. Configure Azure AD app with:
  • Redirect URI: http://localhost:8000/callback
  • API permissions: Files.ReadWrite.All, User.Read, offline_access
  1. Create .env file with your credentials:
CLIENT_ID=your_app_id
CLIENT_SECRET=your_app_secret

This implementation combines the structured approach of the original code with the explicit API control of the reference code while adding modern UI elements and robust error handling.

About

python sample codes to connect to Microsoft Onedrive

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages