diff --git a/.coderabbit.yaml b/.coderabbit.yaml index afc8b2182f..46ccd26870 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -91,7 +91,6 @@ reviews: tools: phpstan: enabled: true - config_file: "phpstan.neon" phpcs: enabled: false phpmd: diff --git a/.cursor/rules/coderabbit-fixes-stay-local.mdc b/.cursor/rules/coderabbit-fixes-stay-local.mdc new file mode 100644 index 0000000000..e80257f4e6 --- /dev/null +++ b/.cursor/rules/coderabbit-fixes-stay-local.mdc @@ -0,0 +1,12 @@ +--- +description: Do not push CodeRabbit fixes until the user has seen the diff +alwaysApply: true +--- + +# CodeRabbit fixes stay local + +When the work is fixing CodeRabbit comments, do not push the branch. + +Make the changes and stop. Leave them unpushed so the user can read the diff. A CodeRabbit review, a red check, or "fix the comments" is not permission to push, force-push, or open a pull request. + +Push only after the user explicitly says to push in that conversation, once they have seen what changed. diff --git a/config-dist.php b/config-dist.php index fddd1383b6..1d341341db 100644 --- a/config-dist.php +++ b/config-dist.php @@ -174,6 +174,10 @@ function __the_end(){ // $CFG->home_path = 'https://example.com/'; // Legacy: $CFG->setExtension('home_path', $CFG->apphome); +// Temporary log when a launch or Plus token takes LTI config from lti_registration +// instead of lti_key. On unless set false. Remove by February 2027. +// $CFG->setExtension('log_registration_keys', false); + // Temporary ReqScope dump at /reqscope and tool/reqscope. Remove around December 2026. // /admin lists this with the QA settings when it is on. // $CFG->setExtension('reqscope_debug', true); diff --git a/lib/src/Controllers/Admin/Key.php b/lib/src/Controllers/Admin/Key.php index 12a6a08f4c..f867a2c5c4 100644 --- a/lib/src/Controllers/Admin/Key.php +++ b/lib/src/Controllers/Admin/Key.php @@ -18,6 +18,10 @@ public static function routes(Application $app) { self::map($app, self::class, 'clientCheck', self::paths('key/client-id-check')); self::map($app, self::class, 'add', self::paths('key/key-add')); self::map($app, self::class, 'detail', self::paths('key/key-detail')); + self::map($app, self::class, 'registrations', self::paths('key/registrations')); + self::map($app, self::class, 'registrationAdd', self::paths('key/registration-add')); + self::map($app, self::class, 'registrationDetail', self::paths('key/registration-detail')); + self::map($app, self::class, 'registrationFromKey', self::paths('key/registration-from-key')); self::map($app, self::class, 'settings', self::paths('key/key-settings')); self::map($app, self::class, 'requests', self::paths('key/requests')); self::map($app, self::class, 'request', self::paths('key/request-detail')); @@ -46,6 +50,26 @@ public function detail() { $this->view('key/key-detail.php'); } + public function registrations() { + if ( $r = $this->gate('keys.view') ) return $r; + $this->view('key/registrations.php'); + } + + public function registrationAdd() { + if ( $r = $this->gate('keys.add') ) return $r; + $this->view('key/registration-add.php'); + } + + public function registrationDetail() { + if ( $r = $this->gate('keys.detail') ) return $r; + $this->view('key/registration-detail.php'); + } + + public function registrationFromKey() { + if ( $r = $this->gate('keys.add') ) return $r; + $this->view('key/registration-from-key.php'); + } + public function settings() { if ( $r = $this->gate('keys.settings') ) return $r; $this->view('key/key-settings.php'); diff --git a/lib/src/Controllers/Instructor.php b/lib/src/Controllers/Instructor.php index 2dbd0b7b6d..7cf791cd9f 100644 --- a/lib/src/Controllers/Instructor.php +++ b/lib/src/Controllers/Instructor.php @@ -1211,6 +1211,9 @@ public function keyDetail(Request $request) $query_fields, $allow_edit, $allow_delete); if ( $row === CrudForm::CRUD_FAIL || $row === CrudForm::CRUD_SUCCESS ) { + if ( $row === CrudForm::CRUD_SUCCESS && isset($_POST['doUpdate']) ) { + LTIX::clearKeysetCache(U::get($_REQUEST, 'key_id')); + } return new RedirectResponse($from_location); } if ( ! is_array($row) ) { diff --git a/lib/src/Controllers/Settings.php b/lib/src/Controllers/Settings.php index 8fc9dbcb53..4e402d53b1 100644 --- a/lib/src/Controllers/Settings.php +++ b/lib/src/Controllers/Settings.php @@ -1348,6 +1348,9 @@ public function keyDetail(Request $request) $query_fields, $allow_edit, $allow_delete); if ( $row === CrudForm::CRUD_FAIL || $row === CrudForm::CRUD_SUCCESS ) { + if ( $row === CrudForm::CRUD_SUCCESS && isset($_POST['doUpdate']) ) { + LTIX::clearKeysetCache(U::get($_REQUEST, 'key_id')); + } return new RedirectResponse($from_location); } if ( ! is_array($row) ) { diff --git a/lib/src/Controllers/templates/Admin/key/blackboard-detail.php b/lib/src/Controllers/templates/Admin/key/blackboard-detail.php index 622f4917e0..0bcbe65644 100644 --- a/lib/src/Controllers/templates/Admin/key/blackboard-detail.php +++ b/lib/src/Controllers/templates/Admin/key/blackboard-detail.php @@ -1,10 +1,9 @@

LTI 1.3

-Blackboard uses a single issuer for all tenants, but +Blackboard uses one issuer for every school, but since the Blackboard developer portal assigns a Well-Known/KeySet URL that is unique -to each Client ID, it is best to skip creating a reusable Issuer in Tsugi, and instead create a Key for each Tenant, -select "No Global Issuer Selected" and set all the issuer values here -to create a Tenant key. +to each Client ID, skip a reusable issuer in Tsugi and create a key for each client id. +Leave the LTI 1.3 registration unset and set all the issuer values on that key. The Deployment ID is provided when you place Tsugi into a Blackboard instance using the Client ID. For Blackboard, the following are the typical values for the Tsugi items: diff --git a/lib/src/Controllers/templates/Admin/key/canvas-detail.php b/lib/src/Controllers/templates/Admin/key/canvas-detail.php index e12ccda612..06924c2149 100644 --- a/lib/src/Controllers/templates/Admin/key/canvas-detail.php +++ b/lib/src/Controllers/templates/Admin/key/canvas-detail.php @@ -1,10 +1,10 @@

Canvas LTI 1.3

-To use LTI 1.3 in Canvas, first create a Tsugi Tenant using a temporary +To use LTI 1.3 in Canvas, first create a Tsugi key using a temporary Client ID such as temporary-42-oertufgh. Make sure it is random enough to be unique across issuers as Tsugi prohibits duplicate (issuer, client_id) records system wide. -Save the Tenant in Tsugi and use the +Save the key in Tsugi and use the LTI values like JWKs URL shown by Tsugi to create a Developer Key in Canvas.

@@ -12,8 +12,8 @@

When the Developer Key is created, Canvas will assign a real Client ID (for example -38288000000000436). Edit the Tsugi Tenant and replace the -temporary Client ID with the value assigned by Canvas and save the Tenant. +38288000000000436). Edit the Tsugi key and replace the +temporary Client ID with the value assigned by Canvas and save the key.

@@ -26,7 +26,7 @@

The Deployment ID is optional in Tsugi and may be left blank to accept launches from any Canvas deployment using that issuer/client pair. -If you enter a Deployment ID on the Tenant, launches will be restricted +If you enter a Deployment ID on the key, launches will be restricted to that specific Canvas deployment (i.e. it might just be one course).

To use LTI 1.1 in Canvas, create your key with a title, key, and secret and come back here to view the XML-based Canvas auto-installation URL. Auto-installation of LTI 1.1 tools -in Canvas is on a per-Tenant basis. +in Canvas is on a per-key basis.

diff --git a/lib/src/Controllers/templates/Admin/key/client-id-check.php b/lib/src/Controllers/templates/Admin/key/client-id-check.php index eed0c204bd..b63ce07c4c 100644 --- a/lib/src/Controllers/templates/Admin/key/client-id-check.php +++ b/lib/src/Controllers/templates/Admin/key/client-id-check.php @@ -41,7 +41,7 @@ echo \Tsugi\Services\Admin\AdminService::issuerClientDuplicateNotice(); ?>

- Tenant Keys + Keys Client Id Check Admin

diff --git a/lib/src/Controllers/templates/Admin/key/index.php b/lib/src/Controllers/templates/Admin/key/index.php index 77ea72a933..82e64a792a 100644 --- a/lib/src/Controllers/templates/Admin/key/index.php +++ b/lib/src/Controllers/templates/Admin/key/index.php @@ -16,12 +16,15 @@ $rows = $PDOX->queryDie($patch_sql); $query_parms = array(); -$searchfields = array("K.key_id", "key_title", "key_key", "deploy_key", "K.login_at", "K.updated_at", "K.user_id", "K.lms_client"); +$searchfields = array("K.key_id", "key_title", "key_key", "deploy_key", "K.login_at", "K.updated_at", "K.user_id", "K.lms_client", "R.issuer", "R.client_id"); $sql = "SELECT K.key_id AS key_id, key_title, key_key, secret, lms_issuer, K.lms_client AS lms_client, lms_oidc_auth, lms_keyset_url, lms_token_url, deploy_key, K.login_at AS login_at, K.updated_at as updated_at, - K.user_id AS user_id + K.user_id AS user_id, K.lti_registration_id AS lti_registration_id, + R.issuer AS registration_issuer, R.client_id AS registration_client FROM {$CFG->dbprefix}lti_key AS K + LEFT JOIN {$CFG->dbprefix}lti_registration AS R + ON R.lti_registration_id = K.lti_registration_id "; $newsql = Table::pagedQuery($sql, $query_parms, $searchfields); @@ -34,8 +37,13 @@ $newrow['key'] = $row['key_key']; if ( !empty($row['key_title']) ) $newrow['key'] = $row['key_title']; $newrow['key_type'] = \Tsugi\Services\Admin\AdminService::keyTypeLabel($row); + $newrow['_html_key_type'] = \Tsugi\Services\Admin\AdminService::keyTypeHtml($row); $issuer_key = $row['lms_issuer']; $client_id = $row['lms_client']; + if ( empty($issuer_key) && empty($client_id) && ! empty($row['registration_issuer']) ) { + $issuer_key = $row['registration_issuer']; + $client_id = $row['registration_client']; + } $issuer_display = ''; if ( !empty($issuer_key) || !empty($client_id) ) { if ( !empty($issuer_key) ) { @@ -64,9 +72,10 @@ $OUTPUT->flashMessages(); echo \Tsugi\Services\Admin\AdminService::clientIdCheckNotices(); ?> -

LTI Tenants (Keys)

+

Keys / Deployments

- Tenant Keys + Registrations + Keys providekeys ) { ?> Key Requests @@ -75,11 +84,12 @@

-You have no Tenant keys for this system. +You have no keys for this system.

"key-add" + "Insert Registration" => "registration-add", + "Insert Key" => "key-add" ); Table::pagedTable($newrows, $searchfields, false, "key-detail", false, $extra_buttons); // echo("
\n");print_r($newrows);echo("
\n"); diff --git a/lib/src/Controllers/templates/Admin/key/key-add.php b/lib/src/Controllers/templates/Admin/key/key-add.php index 2453f21d6a..9332426f7c 100644 --- a/lib/src/Controllers/templates/Admin/key/key-add.php +++ b/lib/src/Controllers/templates/Admin/key/key-add.php @@ -17,13 +17,12 @@ $from_location = LTIX::curPageUrlFolder(); $tablename = "{$CFG->dbprefix}lti_key"; -$fields = array('key_title', 'plus', 'key_key', 'key_sha256', 'secret', +$fields = array('key_title', 'plus', 'user_id', 'key_key', 'key_sha256', 'secret', 'lms_issuer', 'lms_issuer_sha256', 'lms_client', 'deploy_key', 'deploy_sha256', 'lms_oidc_auth', 'lms_keyset_url', 'lms_token_url', 'lms_token_audience', 'created_at', 'updated_at', - 'user_id', ); $titles = array( @@ -65,6 +64,10 @@ } if ( isset($_POST['doSave']) && count($_POST) > 0 ) { + if ( ! \Tsugi\Services\Admin\AdminService::applyPostedRegistrationToKey() ) { + header("Location: key-add"); + return; + } $lms_issuer = U::get($_POST, 'lms_issuer'); $lms_client = U::get($_POST, 'lms_client'); $identity_message = LTI::ascii255First(array( @@ -99,7 +102,9 @@ if ( isset($_POST['doSave']) ) { $binaryHex['guid'] = \Tsugi\Core\Guid::uuid7(); } -$retval = CrudForm::handleInsert($tablename, $fields, $binaryHex); +$save_fields = $fields; +$save_fields[] = 'lti_registration_id'; +$retval = CrudForm::handleInsert($tablename, $save_fields, $binaryHex); if ( $retval == CrudForm::CRUD_SUCCESS || $retval == CrudForm::CRUD_FAIL ) { header("Location: $from_location"); return; @@ -111,7 +116,7 @@ $OUTPUT->flashMessages(); ?> -

Adding Tsugi Tenant/Key +

Adding Key Exit