diff --git a/README.md b/README.md index b0331d2c..58faccd1 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,7 @@ $resource = LTI\LTI_Deep_Link_Resource::new() Everything is set to return the resource to the platform. There are two methods of doing this. -The following method will output the html for an aut-posting form for you. +The following method will output the html for an auto-posting form for you. ```php $dl->output_response_form([$resource]); ``` @@ -209,6 +209,12 @@ Alternatively you can just request the signed JWT that will need posting back to $dl->get_response_jwt([$resource]); ``` +If you've created a JWKS endpoint with `LTI\JWKS_Endpoint::new()`, the kid used in the endpoint can be provided as an additional parameter. +```php +$dl->get_response_jwt([$resource], 'a_unique_KID'); + +``` + ## Calling Services ### Names and Roles Service diff --git a/src/lti/LTI_Assignments_Grades_Service.php b/src/lti/LTI_Assignments_Grades_Service.php index ffd1cde0..08981659 100644 --- a/src/lti/LTI_Assignments_Grades_Service.php +++ b/src/lti/LTI_Assignments_Grades_Service.php @@ -54,8 +54,8 @@ public function find_or_create_lineitem(LTI_Lineitem $new_line_item) { 'application/vnd.ims.lis.v2.lineitemcontainer+json' ); foreach ($line_items['body'] as $line_item) { - if (empty($new_line_item->get_resource_id()) || $line_item['resourceId'] == $new_line_item->get_resource_id()) { - if (empty($new_line_item->get_tag()) || $line_item['tag'] == $new_line_item->get_tag()) { + if (empty($new_line_item->get_resource_id()) || (isset($line_item['resourceId']) && $line_item['resourceId'] == $new_line_item->get_resource_id())) { + if (empty($new_line_item->get_tag()) || (isset($line_item['tag']) && $line_item['tag'] == $new_line_item->get_tag())) { return new LTI_Lineitem($line_item); } } @@ -88,4 +88,4 @@ public function get_grades(LTI_Lineitem $lineitem) { return $scores['body']; } } -?> \ No newline at end of file +?> diff --git a/src/lti/LTI_Deep_Link.php b/src/lti/LTI_Deep_Link.php index c87cb0da..11fb5f76 100644 --- a/src/lti/LTI_Deep_Link.php +++ b/src/lti/LTI_Deep_Link.php @@ -14,10 +14,10 @@ public function __construct($registration, $deployment_id, $deep_link_settings) $this->deep_link_settings = $deep_link_settings; } - public function get_response_jwt($resources) { + public function get_response_jwt($resources, string $kid = null) { $message_jwt = [ "iss" => $this->registration->get_client_id(), - "aud" => [$this->registration->get_issuer()], + "aud" => $this->registration->get_issuer(), "exp" => time() + 600, "iat" => time(), "nonce" => 'nonce' . hash('sha256', random_bytes(64)), @@ -25,13 +25,19 @@ public function get_response_jwt($resources) { "https://purl.imsglobal.org/spec/lti/claim/message_type" => "LtiDeepLinkingResponse", "https://purl.imsglobal.org/spec/lti/claim/version" => "1.3.0", "https://purl.imsglobal.org/spec/lti-dl/claim/content_items" => array_map(function($resource) { return $resource->to_array(); }, $resources), - "https://purl.imsglobal.org/spec/lti-dl/claim/data" => $this->deep_link_settings['data'], + "https://purl.imsglobal.org/spec/lti-dl/claim/data" => $this->deep_link_settings['data']?? "", ]; - return JWT::encode($message_jwt, $this->registration->get_tool_private_key(), 'RS256', $this->registration->get_kid()); + + return JWT::encode( + $message_jwt, + $this->registration->get_tool_private_key(), + 'RS256', + is_null($kid) ? $this->registration->get_kid() : $kid + ); } - public function output_response_form($resources) { - $jwt = $this->get_response_jwt($resources); + public function output_response_form($resources, string $kid = null) { + $jwt = $this->get_response_jwt($resources, $kid); ?>