Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version
([Finding notes](docs/notes.md#finding-notes)).
- **Paste a Drive folder's link.** A Google Drive connection's Root folder and shared drive take the link from the
browser's address bar as well as the bare id, so limiting imports to one folder is a paste, not hunting for the id.
- **Sign in to Dropbox, OneDrive or Google Drive with no app of your own.** Their connections now have **Sign in
with Dropbox** (Microsoft, Google): the service's page opens in a new tab, Lens runs `rclone authorize` on its own
server, and you paste back the address the tab ends on, or nothing at all when the browser runs where Lens does.
No rclone to install on another computer, and no Google Cloud app needed for Drive. Pasting a token still works.
Agents do the same through `POST /api/v1/sources/rclone-signin`
([Storage sources](docs/processing.md#storage-sources)).

## 0.10.0 <small>October 15, 2026</small> {id="0.10.0"}

Expand Down
19 changes: 17 additions & 2 deletions docs/processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,23 @@ Admins can also import chosen files of a source once, without watching their fol
files, then Import (`POST /api/v1/import/source`). The listing marks files that are assets already, and where.

- Credentials are encrypted in the database (AES-GCM, key from `ARCHIVE_SECRET_KEY` or `data_dir/secret.key`) and given
to rclone in a private temporary config file per call. For Dropbox, Drive and OneDrive, paste the token from
`rclone authorize dropbox` (or drive, onedrive); tokens rclone refreshes are saved back.
to rclone in a private temporary config file per call; tokens rclone refreshes are saved back.
- **Dropbox, OneDrive, and Google Drive as a Google account sign in through rclone on the Lens server**, with nothing
to install elsewhere and no app of your own: Sign in with Dropbox (or Microsoft, Google) opens the service's page in
a new tab, which asks you to allow rclone, the tool Lens connects with. Afterwards the service sends that tab to
`http://127.0.0.1:53682/?state=…&code=…`, where `rclone authorize` waits on the server. When your browser runs on
the same machine as Lens that reaches rclone and the dialog carries on by itself; otherwise the page doesn't load:
copy its address from the address bar and paste it into the dialog. Lens passes only that address's state, code and
error on to rclone, and only when the state is this sign-in's. The connection is then made and tested (OneDrive's
own drive filled in), and the dialog goes on to pick a folder. One sign-in runs at a time (rclone listens on one
port), each for ten minutes. A connection whose token stopped working shows Sign in again. Pasting the token
`rclone authorize dropbox` (or drive, onedrive) prints on another computer still works: Paste a token from rclone
instead.
- Agents sign in through rclone the same way: `POST /api/v1/sources/rclone-signin` with `{"type": "dropbox"}` (or
`{"source": <id>}`, and `params`) answers `{id, url, port}`; the person opens `url`, and the agent posts the address
they end on to `POST /api/v1/sources/rclone-signin/{id}` (`{"address": …}`), which answers `{connected: <id>}`
(400: not this sign-in's address, still waiting; 410: cancelled, refused or ran out). `DELETE` stops it. Audited as
`source.signin`.
- Google Drive can also sign in as a service account: choose Service account and upload its JSON key file
(`service_account_credentials`). Share the folders Lens should read with the account's address, or give a shared
drive ID (`team_drive`); in Google Workspace, `impersonate` reads a user's own Drive through domain-wide delegation.
Expand Down
53 changes: 52 additions & 1 deletion fastapi_backend/app/api/v1/routes/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
from fastapi import APIRouter, BackgroundTasks, HTTPException, Request

from app.api.deps import Acl, AdminReader, AdminWriter, Cfg, CurrentUser, Db
from app.domain import auth, sources, store
from app.domain import auth, rclone_signin, sources, store
from app.domain.store import DB
from app.schemas.admin import Started
from app.schemas.common import Created, Ok
from app.schemas.sources import (
Backend,
BrowseEntry,
RcloneSignIn,
RcloneSignInFinish,
RcloneSignInStart,
RcloneSignInState,
RoutedMessage,
RoutePreviewRequest,
Source,
Expand Down Expand Up @@ -80,6 +84,53 @@ def update_source(sid: int, body: SourceUpdate, user: AdminWriter, db: Db, cfg:
return SourceUpdated(health=sources.test(db, cfg, sid))


@router.post("/sources/rclone-signin")
def start_rclone_signin(body: RcloneSignInStart, user: AdminWriter, db: Db, cfg: Cfg) -> RcloneSignIn:
"""Connect Google Drive (with no Google app set up here), Dropbox or OneDrive by signing in through rclone on this
server, or sign a connection in again (`source`). Open `url` in a browser and sign in; the service then sends the
browser to http://127.0.0.1:53682/?…, which only loads on the machine Lens runs on. Hand that address to
POST /sources/rclone-signin/{id}, which makes the connection. One at a time: this ends any other."""
if body.source is None and body.type is None:
raise HTTPException(400, "say which type of connection to make, or which connection to sign in again")
try:
fid, url, port = rclone_signin.start(db, cfg, body.type, body.params, body.name, body.source, by=user.email)
except KeyError:
raise HTTPException(404, "not found") from None
except (ValueError, RuntimeError) as e:
raise HTTPException(400, str(e)) from None
row = db.one("SELECT expires_at FROM $r", r=store.R("rclone_signin", fid))
return RcloneSignIn(id=fid, url=url, port=port, expires_at=row["expires_at"])


@router.post("/sources/rclone-signin/{fid}")
def finish_rclone_signin(fid: str, body: RcloneSignInFinish, user: AdminWriter, db: Db, cfg: Cfg) -> RcloneSignInState:
"""Finish signing in through rclone with the address the browser ended on (`address`), or, without one, look
whether rclone already got it. Answers the connection, made and tested, or none while it waits. 400: that address
isn't this sign-in's, and it's still waiting for the right one; 410: it didn't work (cancelled, refused, ran out),
and it's over; start again. Audited as `source.signin`."""
try:
sid = rclone_signin.finish(db, cfg, fid, body.address)
except KeyError:
raise HTTPException(404, "no such sign-in: it finished, ran out or was cancelled") from None
except rclone_signin.WrongAddress as e:
raise HTTPException(400, str(e)) from None
except ValueError as e:
raise HTTPException(410, str(e)) from None
if sid is not None:
auth.audit(db, user.as_audit(), "source.signin", f"storage_source:{sid}", ["rclone"])
return RcloneSignInState(connected=sid)


@router.delete("/sources/rclone-signin/{fid}")
def cancel_rclone_signin(fid: str, user: AdminWriter, db: Db) -> Ok:
"""Stop a sign-in through rclone."""
try:
rclone_signin.cancel(db, fid)
except KeyError:
raise HTTPException(404, "no such sign-in") from None
return Ok()


@router.delete("/sources/{sid}")
def delete_source(sid: int, user: AdminWriter, db: Db) -> Ok:
"""Remove a source and its watched folders."""
Expand Down
Loading
Loading