Skip to content

Implement token exchange from OCM#57234

Open
enriquepablo wants to merge 66 commits intonextcloud:masterfrom
enriquepablo:master
Open

Implement token exchange from OCM#57234
enriquepablo wants to merge 66 commits intonextcloud:masterfrom
enriquepablo:master

Conversation

@enriquepablo
Copy link
Copy Markdown

@enriquepablo enriquepablo commented Dec 23, 2025

See #57152 #57166

Summary

This PR implements the token exchange flow from OCM, allowing Nextcloud to use bearer auth with short lived tokens. This opens up interoperability with OpenCloud/ownCloud OCIS and the possibility to implement webapp shares in the future, which requires this.

Discussion

This is a preliminary PR for discussion. If this goes through there are some things missing with which we'll be grateful to get some guidance:

  • docs and tests
  • keeping retrieved access tokens in the db
  • removing tokens when removing shares

There is also the question that for access tokens, we are keeping a reference to the corresponding refresh token in the uid field of the access token db record.

Prerequisite

This needs nextcloud/3rdparty#2413 before merging

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 7, 2026

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@enriquepablo
Copy link
Copy Markdown
Author

Disclaimer: Some of the code in this PR (mainly regarding the tests) was generated by Claude Opus 4.5. I have provided it with very specific prompts, and thoroughly reviewed the output.

enriquepablo and others added 26 commits May 6, 2026 09:51
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
…old shares

Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
…al shares table

Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
…pendently

Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
…fresh access tokens

Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
- Align 3rdparty submodule with master
- Add baseline entry for the extra getFederationIdFromSharedSecret call
  introduced for refresh-token flow in RequestHandlerController

Signed-off-by: Micke Nordin <kano@sunet.se>
exchangeRefreshToken hardcoded https:// for OCM discovery, breaking
federated shares against http remotes (e.g. integration test setup).
Use $this->secure to pick the scheme.

Signed-off-by: Micke Nordin <kano@sunet.se>
Master's TEMPORARY_TOKEN-via-Bearer rejection (725f5be) blocked the
PR's own OCM access tokens, which are intentionally TEMPORARY_TOKEN
delivered via Bearer. Mark the OCM tokens with a well-known name and
exempt them from the rejection.

Signed-off-by: Micke Nordin <kano@sunet.se>
Signed-off-by: Micke Nordin <kano@sunet.se>
Re-run build/autoloaderchecker.sh so the new
Version1037Date20260306120000 migration is picked up and the duplicate
entries for Version1038/Version1039 are removed.

Signed-off-by: Micke Nordin <kano@sunet.se>
By using a JWT that the receiver can verify against a public key, we
make it easy for third party services to validate the token
independently. This is relevant for example in the context of webapp
shares that may defer to a separate service to deliver the actual
webapp.

NOTE: This requires nextcloud/3rdparty#2413 to
be merged before this.

Signed-off-by: Micke Nordin <kano@sunet.se>
mickenordin added a commit to enriquepablo/server that referenced this pull request May 6, 2026
Combines the rebased kano-dual-stack-rfc-9421-http-sig PR (RFC 9421
HTTP signature support, OCM Ed25519 keys, JWKS endpoint, occ key
management) with enriquepablo's OCM token-exchange and JWT access
tokens. The exchange-token flow lives on top of the new RFC 9421
signing path (see the follow-up federatedfilesharing fix).

# Conflicts:
#	lib/private/OCM/OCMDiscoveryService.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants