5.1 KiB
OAuth Setup Guide for NUNA Tools
This guide will help you set up OAuth credentials for both Google Drive and OneDrive.
Part 1: Google Drive OAuth Setup
Step 1: Create Google Cloud Project
- Go to Google Cloud Console
- Click on the project dropdown at the top
- Click "New Project"
- Enter project name:
NUNA Drive Cleanup(or any name you prefer) - Click "Create"
Step 2: Enable Google Drive API
- In the Google Cloud Console, go to "APIs & Services" → "Library"
- Search for "Google Drive API"
- Click on it and click "Enable"
Step 3: Create OAuth Credentials
-
Go to "APIs & Services" → "Credentials"
-
Click "+ CREATE CREDENTIALS" → "OAuth client ID"
-
If prompted, configure the OAuth consent screen first:
- User Type: External (unless you have a Google Workspace)
- App name:
NUNA Drive Cleanup - User support email: Your email
- Developer contact: Your email
- Click "Save and Continue"
- Scopes: Click "Add or Remove Scopes", search and add:
https://www.googleapis.com/auth/drive.metadata.readonlyhttps://www.googleapis.com/auth/drive(for trash functionality)
- Click "Save and Continue"
- Test users: Add your email address
- Click "Save and Continue"
- Click "Back to Dashboard"
-
Now create the OAuth client ID:
- Application type: Desktop app
- Name:
NUNA Drive Cleanup Client - Click "Create"
-
Download the credentials:
- Click the download icon (⬇️) next to your newly created OAuth client
- Save the file as
credentials.jsonin theJ:\NUNAdirectory
Step 4: Verify Setup
Run this command to test:
python gdrive_cleanup.py audit --top 5
The first time, it will open a browser for authentication and create token.json.
Part 2: OneDrive OAuth Setup (Microsoft Graph)
Step 1: Create Azure App Registration
- Go to Azure Portal
- Search for "Azure Active Directory" or "Microsoft Entra ID"
- Click "App registrations" in the left menu
- Click "+ New registration"
Step 2: Register the Application
- Name:
NUNA OneDrive Import(or any name) - Supported account types:
- Select "Accounts in any organizational directory and personal Microsoft accounts" (most common)
- OR select what matches your needs
- Redirect URI: Leave empty (we'll use device code flow)
- Click "Register"
Step 3: Configure Authentication
- In your app, go to "Authentication" in the left menu
- Under "Advanced settings", find "Allow public client flows"
- Set it to "Yes"
- Click "Save"
Step 4: Add API Permissions
- Go to "API permissions" in the left menu
- Click "+ Add a permission"
- Select "Microsoft Graph"
- Select "Delegated permissions"
- Add these permissions:
Files.ReadWrite.All- Read and write all filesUser.Read- Sign in and read user profile
- Click "Add permissions"
Note: For personal Microsoft accounts, Files.ReadWrite.All should work without admin consent. For organizational accounts, you may need admin consent.
Step 5: Get Client ID
- In your app overview page, copy the "Application (client) ID"
- It looks like:
12345678-1234-1234-1234-123456789abc
Step 6: Set Environment Variable
Windows PowerShell:
$env:ONEDRIVE_CLIENT_ID = "YOUR_CLIENT_ID_HERE"
Windows Command Prompt:
set ONEDRIVE_CLIENT_ID=YOUR_CLIENT_ID_HERE
Permanent (PowerShell - User level):
[System.Environment]::SetEnvironmentVariable('ONEDRIVE_CLIENT_ID', 'YOUR_CLIENT_ID_HERE', 'User')
Permanent (Command Prompt):
setx ONEDRIVE_CLIENT_ID "YOUR_CLIENT_ID_HERE"
Note: After setting permanently, restart your terminal/PowerShell.
Step 7: Verify Setup
Run this command to test (dry-run):
python dropbox_to_onedrive.py --dropbox-url "YOUR_DROPBOX_URL" --dry-run
The first time, it will print a device code and URL. Open the URL in your browser and enter the code to authenticate.
Quick Setup Scripts
I've created helper scripts to make this easier. See:
setup-google-oauth.ps1- Interactive Google OAuth setupsetup-onedrive-oauth.ps1- Interactive OneDrive OAuth setup
Troubleshooting
Google Drive Issues:
- 403 Error: Make sure Google Drive API is enabled
- Credentials not found: Ensure
credentials.jsonis in theJ:\NUNAdirectory - Scope errors: Check that you added the required scopes in OAuth consent screen
OneDrive Issues:
- Client ID not found: Make sure environment variable is set correctly
- Permission denied: Check that
Files.ReadWrite.Allpermission is added - Device code expired: The code expires after 15 minutes, run the command again
Security Notes
- Never commit
credentials.jsonortoken.jsonto version control - These files are already in
.gitignore - Keep your OAuth credentials secure
- Revoke access if credentials are compromised