Skip to content

[SE-664] APIv3 endpoint for collaboration tokens for documents (behind feature flag) - #26279

Open
judithroth wants to merge 3 commits into
devfrom
feature/se-664-api-token-gen-behind-feature-flag
Open

judithroth wants to merge 3 commits into
devfrom
feature/se-664-api-token-gen-behind-feature-flag

Conversation

@judithroth

Copy link
Copy Markdown
Contributor

Ticket

https://community.openproject.org/wp/SE-664

What are you trying to accomplish?

Enable to get collaboration tokens for documents via the APIv3, so that e.g. the mobile app can get a token and connect to Hocuspocus. This is behind a feature flag for now, so the mobile team can test earlier. This is a spin-off of #25879 , which I would also like to finish to get rid of the feature flag, but likely takes a little more time.

What approach did you choose and why?

Add new APIv3 endpoint which generates a token, which can be used to connect to Hocuspocus for that document. Optionally, it allows to send the previous token with the request, so it can be revoked.

Out of scope (will be a separate PR)

  • Replace existing token refresh mechanism that is used in documents in the frontend.

AI involvement

Collaborative – AI generated a substantial part of the code; I reviewed and understand every line.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@judithroth judithroth self-assigned this Oct 23, 2026
@judithroth
judithroth requested a balanced review from Copilot October 23, 2026 14:26
@github-actions github-actions Bot added the ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line. label Oct 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Anonymous callers with public-document access can receive collaboration tokens that cannot authenticate Hocuspocus's document requests.

1 open issue
What changed in this PR

Adds a feature-flagged APIv3 endpoint so mobile clients can obtain document collaboration tokens for Hocuspocus, while retaining the existing frontend refresh mechanism.

Changes:

  • Adds token creation, response metadata, and document action links behind documents_collaboration_token_api.
  • Supports optional previous-token validation and delayed revocation.
  • Adds API documentation and tests for permissions, encryption, token replacement, and feature gating.
File Description
modules/​documents/​spec/​support/​shared/​collaboration_token_endpoint.rb Shared endpoint authorization and response tests.
modules/​documents/​spec/​services/​documents/​oauth/​token_with_metadata_service_spec.rb Tests token creation, validation, revocation, and rollback.
modules/​documents/​spec/​services/​documents/​oauth/​ensure_application_service_spec.rb Tests collaboration-token identification.
modules/​documents/​spec/​services/​documents/​oauth/​decrypt_token_service_spec.rb Tests decryption and invalid-token handling.
modules/​documents/​spec/​requests/​api/​v3/​documents/​collaboration_token_resource_spec.rb Covers endpoint responses and token replacement.
modules/​documents/​spec/​models/​document_spec.rb Tests collaboration availability.
modules/​documents/​spec/​controllers/​documents/​refresh_tokens_controller_spec.rb Tests rejection of non-collaborative documents.
modules/​documents/​spec/​api/​v3/​utilities/​path_helper_spec.rb Tests the token endpoint path.
modules/​documents/​spec/​api/​v3/​documents/​document_representer_rendering_spec.rb Tests action-link visibility and caching.
modules/​documents/​lib/​open_project/​documents/​engine.rb Registers the feature flag and API path.
modules/​documents/​lib/​api/​v3/​documents/​documents_api.rb Mounts the endpoint and memoizes document lookup.
modules/​documents/​lib/​api/​v3/​documents/​document_representer.rb Adds the conditional token action link.
modules/​documents/​lib/​api/​v3/​documents/​collaboration_token_representer.rb Defines token response fields and links.
modules/​documents/​lib/​api/​v3/​documents/​collaboration_token_api.rb Implements guarded token creation and error responses.
modules/​documents/​config/​locales/​en.yml Adds token-related error messages.
modules/​documents/​app/​services/​documents/​oauth/​token_with_metadata_service.rb Adds preconditions and transactional token replacement.
modules/​documents/​app/​services/​documents/​oauth/​token_encryptor.rb Extracts shared cipher configuration.
modules/​documents/​app/​services/​documents/​oauth/​ensure_application_service.rb Identifies collaboration application tokens.
modules/​documents/​app/​services/​documents/​oauth/​encrypt_token_service.rb Uses shared encryption configuration.
modules/​documents/​app/​services/​documents/​oauth/​decrypt_token_service.rb Adds collaboration-token decryption.
modules/​documents/​app/​models/​document.rb Centralizes collaboration availability checks.
modules/​documents/​app/​controllers/​documents/​refresh_tokens_controller.rb Updates token service arguments.
modules/​documents/​app/​controllers/​documents_controller.rb Uses the shared availability check and updated service.
docs/​api/​apiv3/​tags/​documents.yml Documents collaboration connection and refresh steps.
docs/​api/​apiv3/​paths/​document.yml Adds token action links to response examples.
docs/​api/​apiv3/​paths/​document_collaboration_token.yml Documents endpoint inputs, responses, and restrictions.
docs/​api/​apiv3/​openapi-spec.yml Registers the endpoint and response schema.
docs/​api/​apiv3/​components/​schemas/​document_model.yml Documents the conditional token action link.
docs/​api/​apiv3/​components/​schemas/​collaboration_token_model.yml Defines the collaboration-token response schema.

Review effort: Balanced

Comment thread modules/documents/lib/api/v3/documents/collaboration_token_api.rb
@judithroth
judithroth force-pushed the feature/se-664-api-token-gen-behind-feature-flag branch from 6b70314 to e327ee2 Compare October 23, 2026 15:00
judithroth and others added 3 commits October 23, 2026 17:10
https://community.openproject.org/wp/SE-664

- POST /api/v3/documents/:id/collaboration_token creates an encrypted
  token for the collaboration server (Hocuspocus).
- An optional `token` revokes the previous token 30 seconds later; each
  token can be revoked only once (race-free).
- Requests authenticated with a collaboration token (an OAuth token
  issued to the Documents OAuth application) are rejected with 403.
- Includes the OpenAPI docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
https://community.openproject.org/wp/SE-664

They can not connect anyway, so why give them tokens.
Fixing the behaviour for anonymous users on instances that are public
and have a public project with documents is out of scope of this PR
though.
@judithroth
judithroth force-pushed the feature/se-664-api-token-gen-behind-feature-flag branch from e327ee2 to eed5d55 Compare October 23, 2026 15:11
@judithroth
judithroth requested a review from a team October 23, 2026 15:27
@judithroth
judithroth marked this pull request as ready for review October 23, 2026 15:27

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line.

Development

Successfully merging this pull request may close these issues.

2 participants