forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-79675 libraries: upgrade lti1p3 to v5.7.0
- Loading branch information
Showing
24 changed files
with
469 additions
and
101 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
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
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
Oops, something went wrong.