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_Deep_Link.php b/src/lti/LTI_Deep_Link.php index c87cb0da..06631a04 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)), @@ -27,11 +27,17 @@ public function get_response_jwt($resources) { "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'], ]; - 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); ?>