Spaces:
Sleeping
Sleeping
| """One-time Dropbox OAuth setup — generates the refresh token for .env. | |
| Usage: | |
| python scripts/dropbox_auth.py | |
| What it does: | |
| 1. Prints an authorization URL — open it in a browser and click Allow. | |
| 2. Paste the auth code back at the prompt. | |
| 3. Prints the refresh token to copy into DROPBOX_REFRESH_TOKEN in your .env. | |
| After this runs once the refresh token lives in .env and no further browser | |
| interaction is ever needed. The app uses it silently at runtime. | |
| Requirements: pip install dropbox | |
| """ | |
| import sys | |
| try: | |
| import dropbox | |
| from dropbox import DropboxOAuth2FlowNoRedirect | |
| except ImportError: | |
| sys.exit("dropbox package not installed — run: pip install dropbox") | |
| def main() -> None: | |
| app_key = input("Enter DROPBOX_APP_KEY: ").strip() | |
| app_secret = input("Enter DROPBOX_APP_SECRET: ").strip() | |
| auth_flow = DropboxOAuth2FlowNoRedirect( | |
| app_key, | |
| app_secret, | |
| token_access_type="offline", | |
| ) | |
| authorize_url = auth_flow.start() | |
| print("\n--- Step 1 ---") | |
| print("Open this URL in a browser and click Allow:\n") | |
| print(authorize_url) | |
| print() | |
| auth_code = input("--- Step 2 --- Paste the authorization code here: ").strip() | |
| try: | |
| result = auth_flow.finish(auth_code) | |
| except Exception as exc: | |
| sys.exit(f"Auth failed: {exc}") | |
| print("\n--- Done ---") | |
| print("Add these to your .env file:\n") | |
| print(f"DROPBOX_APP_KEY={app_key}") | |
| print(f"DROPBOX_APP_SECRET={app_secret}") | |
| print(f"DROPBOX_REFRESH_TOKEN={result.refresh_token}") | |
| print() | |
| print("The refresh token does not expire. Re-run this script only if you revoke app access.") | |
| if __name__ == "__main__": | |
| main() | |