Spaces:
Sleeping
Sleeping
File size: 1,707 Bytes
7da71bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | """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()
|