forked from 1EdTech/lti-1-3-php-library
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from packbackbooks/mgmt-132-migrations
MGMT-132: Supporting migrations
- Loading branch information
Showing
19 changed files
with
802 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
.phpunit.result.cache | ||
.php_cs.cache | ||
.php-cs-fixer.cache | ||
.vscode | ||
|
||
build | ||
composer.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Packback\Lti1p3\Interfaces; | ||
|
||
use Packback\Lti1p3\LtiDeployment; | ||
use Packback\Lti1p3\LtiMessageLaunch; | ||
|
||
/** | ||
* This is an optional interface if an LTI 1.3 tool supports migrations | ||
* from LTI 1.1 compatible installations. | ||
* | ||
* To use this, just have whatever class you create that implements IDatabase | ||
* also implement this interface. | ||
*/ | ||
interface IMigrationDatabase extends IDatabase | ||
{ | ||
/** | ||
* Using the LtiMessageLaunch return an array of matching LTI 1.1 keys | ||
* | ||
* @return array<\Packback\Lti1p3\Lti1p1Key> | ||
*/ | ||
public function findLti1p1Keys(LtiMessageLaunch $launch): array; | ||
|
||
/** | ||
* Given an LtiMessageLaunch, return true if this tool should migrate from 1.1 to 1.3 | ||
*/ | ||
public function shouldMigrate(LtiMessageLaunch $launch): bool; | ||
|
||
/** | ||
* This method should create a 1.3 deployment in your DB based on the LtiMessageLaunch. | ||
* Previous to this, we validated the oauth_consumer_key_sign to ensure this migration | ||
* can safely occur. | ||
*/ | ||
public function migrateFromLti1p1(LtiMessageLaunch $launch): ?LtiDeployment; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Packback\Lti1p3; | ||
|
||
/** | ||
* Used for migrations from LTI 1.1 to LTI 1.3 | ||
* | ||
* @see IMigrationDatabase | ||
*/ | ||
class Lti1p1Key | ||
{ | ||
private $key; | ||
private $secret; | ||
|
||
public function __construct(array $key = null) | ||
{ | ||
$this->key = $key['key'] ?? null; | ||
$this->secret = $key['secret'] ?? null; | ||
} | ||
|
||
public function getKey() | ||
{ | ||
return $this->key; | ||
} | ||
|
||
public function setKey(array $key) | ||
{ | ||
$this->key = $key; | ||
|
||
return $this; | ||
} | ||
|
||
public function getSecret() | ||
{ | ||
return $this->secret; | ||
} | ||
|
||
public function setSecret(array $secret) | ||
{ | ||
$this->secret = $secret; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Create a signature using the key and secret | ||
* | ||
* @see https://www.imsglobal.org/spec/lti/v1p3/migr#oauth_consumer_key_sign | ||
*/ | ||
public function sign(string $deploymentId, string $iss, string $clientId, string $exp, string $nonce): string | ||
{ | ||
$signatureComponents = [ | ||
$this->getKey(), | ||
$deploymentId, | ||
$iss, | ||
$clientId, | ||
$exp, | ||
$nonce, | ||
]; | ||
|
||
$baseString = implode('&', $signatureComponents); | ||
$utf8String = mb_convert_encoding($baseString, 'utf8', mb_detect_encoding($baseString)); | ||
$hash = hash_hmac('sha256', $utf8String, $this->getSecret(), true); | ||
|
||
return base64_encode($hash); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.