Skip to content

Conversation

erikmd
Copy link
Collaborator

@erikmd erikmd commented Sep 2, 2025

  • Kind: feature

Warning

This PR shares commits with the previous PR #610, so after review both PRs should me merged successively (no squash).

Description

This PR adds support for (Moodle) LTI-based authentication. It relies on prior work in the oauth-moodle-dev branch, with many recent changes and improvements by @MNassimM and @CJs0800, collaborating with @YannickChevalier and me. It adds one main OCaml dependency (irmin-git) to store critical data in a subfolder of /sync. Thanks to a more modular architecture devised by @MNassimM, the email/password authentication will be easier to add - but this addition is left as the topic for a follow-up PR.

Checklist

General items:

Leftover items before the PR can be considered as finalized and ready to be merged:

  • Rebase to cope with the merge of build: update pinned package versions #622
  • DB: Add a version to the Irmin JSON values, to make the key/value databases future-proof w.r.t. migration
  • CLI: Print debug info w.r.t. LTI consumer_key / shared_secret
  • LTI: Read all default parameters (roles, lis_person_name_{given,family,full}, lis_person_contact_email_primary)
  • LTI: Implement an efficient verification of the LTI 1.1 client nonces
  • Doc: Add some full-blown documentation of use_lti (with screenshots) in docs/**.md
  • LTI: Handle custom parameters, typically to open a learn-ocaml exercise or page directly after the LTI Launch step

Note to maintainers

  • Read this wiki page.
  • Make sure the PR has a milestone.
  • Assign yourself before merging.
  • Either do a regular merge:
    • for PRs containing several commits following conventional-commits,
    • or for PRs containing 1 commit shared with a later PR (to preserve the SHA1)
  • Or do a squash-merge:
    • for PRs containing only 1 commit (not shared with a later PR),
    • or for PRs containing several commits that need not be kept in the history;
    • Update the commit message header with a conventional-commit type,
    • Add a footer Close #… if a related issue exists.

MNassimM and others added 29 commits June 3, 2025 11:02
All endpoints previously requiring a token now expect a session.

BREAKING CHANGE: Endpoints and clients using token-based authentication must be updated to use session-based authentication.
All API calls and local_storage interactions in the app/ folder now use session for authentication instead of token.
Add a new  API route that returns the token associated with a given session, enabling clients to retrieve their token server-side without storing it in the frontend.
…or CLI)

Update supported_versions so:
 - legacy token routes are valid Upto v2.0
 - new session routes are valid Since v2.0

Clients ≥ 2.0 negotiate the new API; CLI clients continue to work.

Front-end now uses only the “_s” routes.
This change needed to refactor the decompress-based deflate encoding
Replace the JSON-based storage of session-token-date entries with an Irmin Git-backed key-value store.

Sessions are no longer stored in 'sessions.json' but in an Irmin Git repository ('session_store.git' by default).

Credits: this patch reuses code from oauth-moodle-dev by the following authors.
Co-authored-by: Louis Tariot <[email protected]>
Motivation:
- Learnocaml_store contained Json_codec
- learnocaml_client.ml relies on Json_codec
- Learnocaml_store depends on Learnocaml_api
- Learnocaml_store pulls irmin-git.unix and cryptokit
  - unlike Learnocaml_api
  - and these two dependencies are unneeded for compiling learnocaml_client.ml
Otherwise we'd get:

```
Error loading shared library libgmp.so.10: No such file or directory (needed by /usr/bin/learn-ocaml)
```

cf. https://github.com/ocaml-sf/learn-ocaml/actions/runs/15428646832/job/43421680304?pr=610
…ication support

Introduce LtiIndex to map external LTI user IDs to tokens, and TokenIndex to manage token associations with multiple authentication methods (e.g. idmoodle, email).
This enables future support for LTI and other authentication workflows.

Credits: this patch reuses code from oauth-moodle-dev by the following authors.
Co-authored-by: Alban Gruin <[email protected]>
Co-authored-by: Erik Martin-Dorel <[email protected]>
…rsions

Introduce endpoints for authentication workflows (launch, associate, login, register) in the API.
… template

Add support for LTI user registration and token association in the login overlay, enabling direct and indirect LTI login workflows.

Credits: this patch reuses code from oauth-moodle-dev by the following authors.
Co-authored-by: Alban Gruin <[email protected]>
Co-authored-by: Erik Martin-Dorel <[email protected]>
Co-authored-by: Léo Segond <[email protected]>
…I handler refactor

Introduce a modular authentication layer (learnocaml_auth) with initial LTI (Moodle) support.
Add Launch and Login endpoints to the server for new auth methods.
Refactor API request handling to pass structured http_request and support future extensibility.

Credits: this patch reuses code from oauth-moodle-dev by the following authors.
Co-authored-by: Alban Gruin <[email protected]>
Co-authored-by: Léo Segond <[email protected]>
…tication linking

- Add learnocaml_auth as a separate library with its dependencies in dune.
- Implement secure association between legacy tokens and LTI accounts (Moodle) in the backend.
- Improve  logic and handle POST /associate route with checks and session management.
- Prepare future extensibility for additional authentication methods (email, etc).

Credits: this patch reuses code from oauth-moodle-dev by the following authors.
Co-authored-by: Alban Gruin <[email protected]>
Co-authored-by: Erik Martin-Dorel <[email protected]>
…reation

- Implement  with HMAC validation and nickname handling.
- Handle POST /register route to support LTI account creation and session association.
- Prepare backend for modular registration flows (future email/other methods).

Credits: this patch reuses code from oauth-moodle-dev by the following authors.
Co-authored-by: Alban Gruin <[email protected]>
Co-authored-by: Erik Martin-Dorel <[email protected]>
…login

- Add  executable for LTI flows in dune build.
- Add  utility for form encoding in .
- Refactor token login to use encoded POST body for extensible auth.

Credits: this patch reuses code from oauth-moodle-dev by the following authors.
Co-authored-by: Alban Gruin <[email protected]>
Co-authored-by: Erik Martin-Dorel <[email protected]>
Co-authored-by: Léo Segond <[email protected]>
- Add use_lti boolean flag
- Update encoding/decoding to support the new field
- Default to false if not present

Credits: this patch reuses code from oauth-moodle-dev by the following authors.
Co-authored-by: Alban Gruin <[email protected]>
- The OAuth signature is now really checked again.
- The launch URL now uses req.Api.host when deployed, or localhost in local/dev.
…oauth

- Add a test library for learnocaml_auth with ppx_expect and ppx_inline_test.
- Allow passing the secret directly to check_oauth for easier testing.
- Expose LtiIndex.repo_path for test configuration.
@erikmd erikmd added the kind: feature New user-facing feature. label Sep 2, 2025
@erikmd erikmd marked this pull request as draft September 2, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: feature New user-facing feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants