External drive (Google Drive)
This integration lets a member link their own Google Drive to the document space, to import files from it or to send documents to it.
Principle: client to client
Unlike the NextCloud connector, which drives an external server from the platform with an administrator account and provisions one account per member, this integration passes no authentication data through the platform.
| NextCloud connector | Google Drive external drive | |
|---|---|---|
| Who authenticates | The platform, with an administrator account | The member's browser, with the member's own account |
| Secret held by the platform | NextCloud administrator password | None |
| Tokens stored | Table nextcloud.user, one application token per member | None; the token stays in the memory of the tab |
| Path of the data | External service, platform, browser | Browser and Google, then browser and platform |
| Duration of access | Permanent | The life of the tab, about one hour, renewed by a new consent |
It follows that there is no background synchronization and no permanent "Google Drive" tree in the document space, and that the platform cannot read a member's Drive. The member consents explicitly, in each session, when they click.
How it works
- The member clicks Import from Google Drive in the document space.
- The browser loads the Google Identity Services library and requests an access token, as a
public OAuth 2.0 client with no client secret, with the scope
drive.file. - The Google Picker opens in a frame served by Google. The member selects files.
- The browser downloads the files from the Drive API, then uploads them to the document space
through the usual route,
POST /workspace/document, in the folder that was open. - Export follows the reverse path: the browser reads the document from the platform and sends it to the Drive API, in the folder the member chose.
Native Google documents (Docs, Sheets, Slides, Drawings) are converted on the fly by the
Drive API, to .docx, .xlsx, .pptx and .png respectively.
Why the drive.file scope
The scopes drive and drive.readonly give access to the whole Drive and are classed as
restricted by Google: using them requires having the application verified by Google, a long
procedure with a security audit. The drive.file scope is not restricted.
The Picker makes the trade-off painless: combined with drive.file, it lets the member browse
and select any file of their Drive, and the act of selecting grants the application access to
that one file. The member sees their whole Drive, and the application never receives global
access.
Setting it up
1. Declare the project in the Google Cloud console
- Create or reuse a project at console.cloud.google.com.
- Enable two APIs: Google Drive API and Google Picker API.
- Configure the OAuth consent screen as External. No verification by Google is needed while
only
drive.fileis requested. - Create an OAuth 2.0 client ID of type Web application:
- under authorized JavaScript origins, list every host of the platform, one per line. This is what prevents a third party from reusing the client ID from another site;
- no redirect URI is needed, since the browser flow does not use one.
- Create an API key, which the Picker requires, and restrict it:
- by HTTP referrer, to the hosts of the platform;
- by API, to the Google Picker API only.
- Note the project number, a series of digits: it is the
app-idthe Picker expects.
The client ID, the API key and the project number are public by design: they can be read in the code of any page that uses them. What protects the project are the restrictions set above. There is no secret to store in a Kubernetes secret.
2. Configure the platform
In starter/.env, or in the environment of the Helm chart:
CLOUD_DRIVE_ENABLED=true
CLOUD_DRIVE_GOOGLE_CLIENT_ID=<client-id>.apps.googleusercontent.com
CLOUD_DRIVE_GOOGLE_API_KEY=<api-key>
CLOUD_DRIVE_GOOGLE_APP_ID=<project-number>
These values feed the cloud-drive block of the configuration of the org.entcore.workspace
module in starter/ent-core.yaml, and are passed to the view of the document space.
3. Extend the content security policy
The Picker loads scripts and a frame hosted by Google. The content security policy of the platform must allow these four families of resources:
CLOUD_DRIVE_CSP_SCRIPT_SRC="https://apis.google.com https://accounts.google.com"
CLOUD_DRIVE_CSP_CONNECT_SRC="https://www.googleapis.com https://content.googleapis.com https://accounts.google.com"
CLOUD_DRIVE_CSP_FRAME_SRC="https://docs.google.com https://accounts.google.com"
CLOUD_DRIVE_CSP_IMG_SRC="https://*.googleusercontent.com https://drive-thirdparty.googleusercontent.com"
The four variables are empty by default: while the feature is disabled, no third-party domain is allowed.
SecurityHookRender stores in the session the policy computed for the member. A session already
open keeps the policy in force when it was created: after changing these variables and
redeploying, sign in again for the new policy to apply.
Enabling and disabling
CLOUD_DRIVE_ENABLED=false, the default, removes both buttons from the document space and
injects no Google script into the page. An empty client ID has the same effect.
The import button is also subject to the workspace.create right: a member who cannot upload to
the document space does not see it. The export entry appears in the context menu of a selection
that contains only files.
Scope of the integration
- Consent holds for the current session. A browser client receives only a short-lived access token from Google, so the connection is requested again in the next session.
- Import and export produce a copy. The two spaces stay independent: a document changed on one side is not updated on the other.
- The consent window is opened by the browser. A browser set to block pop-ups prevents the connection, and the member is told so.
- The provider covered is Google Drive. The same hooks are designed to take another provider.
Where the code lives
| Role | File |
|---|---|
| Browser logic: token, picker, import, export | workspace/src/main/resources/public/ts/delegates/cloud-drive.ts |
| Wiring in the controller of the document space | workspace/src/main/resources/public/ts/controller.ts |
| Buttons | workspace/src/main/resources/view-src/workspace.html |
| Passing the configuration to the view | workspace/src/main/java/org/entcore/workspace/controllers/WorkspaceController.java |
| Configuration | starter/ent-core.yaml (the cloud-drive block of the workspace module), starter/.env, and the values of the Helm chart |
These files belong to the core library. A change requires publishing the matching JAR again.