File size: 3,596 Bytes
c2dd918
10d75c6
 
 
 
c2dd918
10d75c6
c2dd918
 
 
10d75c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
title: Dropbox Rclone
emoji: πŸ“¦
colorFrom: blue
colorTo: gray
sdk: docker
app_port: 7860
pinned: false
---

# dropbox-rclone

A Python web app that lets users generate their own **rclone Dropbox configs** using their own Dropbox app credentials. Multiple users can use the app simultaneously β€” each session is completely isolated.

## How it works

1. A user visits the app and enters their Dropbox **Client ID** (app key) and **Client Secret** (app secret).
2. The app redirects them to Dropbox to authorise access.
3. After authorisation, the app exchanges the code for tokens and generates a ready-to-use rclone config block.
4. The user copies the config into their rclone config file.

## Prerequisites

- Python 3.9+
- A Dropbox app ([App Console](https://www.dropbox.com/developers/apps))

## Dropbox app setup

1. Create an app in the [Dropbox App Console](https://www.dropbox.com/developers/apps).
2. Under **OAuth 2 β†’ Redirect URIs**, add the callback URL for your deployment, e.g.:
   - Local development: `http://localhost:5000/callback`
   - Production: `https://your-domain.com/callback`
3. Note the **App key** (Client ID) and **App secret** (Client Secret).

## Running locally

```bash
pip install -r requirements.txt

# Optional but recommended in production:
export SECRET_KEY="$(python -c 'import secrets; print(secrets.token_hex(32))')"

python app.py
# β†’ http://localhost:5000
```

## Running with Gunicorn (recommended for production)

```bash
export SECRET_KEY="a-long-random-string"
export PORT=7860

gunicorn --bind 0.0.0.0:$PORT --workers 2 --threads 2 app:app
```

## Docker

```bash
docker build -t dropbox-rclone .
docker run -p 7860:7860 -e SECRET_KEY="a-long-random-string" dropbox-rclone
```

## Hugging Face Spaces

This repository is ready to deploy on [Hugging Face Spaces](https://huggingface.co/spaces) (free tier) using the Docker SDK.

1. Create a new Space on Hugging Face and choose **Docker** as the SDK.
2. Push this repository (or the `copilot/deploy-to-hugging-face` branch) to the Space.
3. In the Space **Settings β†’ Repository secrets**, add a `SECRET_KEY` secret with a long random value:
   ```
   python -c "import secrets; print(secrets.token_hex(32))"
   ```
4. In your Dropbox app's **OAuth 2 β†’ Redirect URIs**, add:
   ```
   https://<your-space-owner>-<your-space-name>.hf.space/callback
   ```
   The Space URL is shown on the Space overview page.
5. Hugging Face will build and start the container automatically. The app will be available at `https://<your-space-owner>-<your-space-name>.hf.space`.

## Environment variables

| Variable     | Default              | Description                                       |
|--------------|----------------------|---------------------------------------------------|
| `SECRET_KEY` | random (per restart) | Secret key for signing session cookies. **Set this in production.** |
| `PORT`       | `5000`               | Port to listen on when running with `python app.py` |

> **Security note:** Set a stable `SECRET_KEY` in production. Without it, a new random key is generated on every process start, which:
> - Invalidates all existing sessions on restart.
> - Causes session validation failures when using multiple Gunicorn workers (each worker gets its own random key). This will break the OAuth flow for most users in a multi-worker setup.

## Concurrency

The app stores all per-user state in signed, server-side session cookies, so there is no shared mutable state between requests. It scales horizontally β€” run as many Gunicorn workers or container replicas as you need.