Skip to content

Commit

Permalink
auto-deployment-id creation now uses correct param source
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispittman committed Apr 30, 2022
1 parent c70afad commit f6823a1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/LtiTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,37 @@ protected function onError() : void
*
* This function allows tools to bypass CeLTIc's mandatory deployment_id checks, by
* assuming that the tool has been successfully deployed once, and copying that
* deployment with the new deployment_id provided in the request. Functionally, this
* is likely he same thing you'd be asking your users to do by hand.
* deployment with the new deployment_id provided in the request. (Functionally, this
* is likely the same thing you'd be asking your users to do by hand.)
*/
public function createDeploymentIdFromExistingPlatform() : void
{
if (request('iss')!==null && request('client_id')!==null && request('lti_deployment_id')!==null) {
$platform_id = request('iss');
$client_id = request('client_id');
$deployment_id = request('lti_deployment_id');
$messageParms = collect($this->getMessageParameters());
$platform_id = $messageParms->get('platform_id'); //request('iss');
$client_id = $messageParms->get('oauth_consumer_key'); //request('client_id');
$deployment_id = $messageParms->get('deployment_id'); //request('lti_deployment_id');

// if the JWT parms indicate a platform...
if ($platform_id!==null && $client_id!==null && $deployment_id!==null) {
$platform = DB::table('lti2_consumer')
->where('platform_id', $platform_id)
->where('client_id', $client_id)
->where('deployment_id', $deployment_id)
->get();
// ... and it's not one we have yet
if (count($platform) === 0) {
$platform = DB::table('lti2_consumer')
->where('platform_id', $platform_id)
->where('client_id', $client_id)
->get();
// ... but which shares a platformID and clientID with an existing deployment
if (count($platform) > 0) {
// ... clone that deployment, but with this deployment's deploymentID.
$new_platform = (array)$platform[0];
unset($new_platform['consumer_pk']);
$new_platform['deployment_id'] = $deployment_id;
DB::table('lti2_consumer')->insert($new_platform);
$this->platform = \ceLTIc\LTI\Platform::fromPlatformId($platform_id, $client_id, $deployment_id, $this->dataConnector);
}
}
}
Expand Down

0 comments on commit f6823a1

Please sign in to comment.