Skip to content

Commit 731813c

Browse files
authored
Merge pull request 1EdTech#63 from packbackbooks/podb-603-error-msg
PODB-603: Update error message for missing registration
2 parents d89c674 + de328e5 commit 731813c

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/LtiMessageLaunch.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ class LtiMessageLaunch
2828
public const ERR_INVALID_ID_TOKEN = 'Invalid id_token, JWT must contain 3 parts';
2929
public const ERR_MISSING_NONCE = 'Missing Nonce.';
3030
public const ERR_INVALID_NONCE = 'Invalid Nonce.';
31-
public const ERR_MISSING_REGISTRATION = 'Registration not found. Please have your admin confirm your Issuer URL, client ID, and deployment ID.';
31+
32+
/**
33+
* :issuerUrl and :clientId are used to substitute the queried issuerUrl
34+
* and clientId. Do not change those substrings without changing how the
35+
* error message is built.
36+
*/
37+
public const ERR_MISSING_REGISTRATION = 'LTI 1.3 Registration not found for Issuer :issuerUrl and Client ID :clientId. Please make sure the LMS has provided the right information, and that the LMS has been registered correctly in the tool.';
38+
3239
public const ERR_CLIENT_NOT_REGISTERED = 'Client id not registered for this issuer.';
3340
public const ERR_NO_KID = 'No KID specified in the JWT Header.';
3441
public const ERR_INVALID_SIGNATURE = 'Invalid signature on id_token';
@@ -276,6 +283,19 @@ public function getLaunchId()
276283
return $this->launch_id;
277284
}
278285

286+
public static function getMissingRegistrationErrorMsg(string $issuerUrl, ?string $clientId = null): string
287+
{
288+
// Guard against client ID being null
289+
if (!isset($clientId)) {
290+
$clientId = '(N/A)';
291+
}
292+
293+
$search = [':issuerUrl', ':clientId'];
294+
$replace = [$issuerUrl, $clientId];
295+
296+
return str_replace($search, $replace, static::ERR_MISSING_REGISTRATION);
297+
}
298+
279299
private function getPublicKey()
280300
{
281301
$request = new ServiceRequest(
@@ -403,15 +423,16 @@ private function validateNonce()
403423
private function validateRegistration()
404424
{
405425
// Find registration.
406-
$client_id = is_array($this->jwt['body']['aud']) ? $this->jwt['body']['aud'][0] : $this->jwt['body']['aud'];
407-
$this->registration = $this->db->findRegistrationByIssuer($this->jwt['body']['iss'], $client_id);
426+
$clientId = is_array($this->jwt['body']['aud']) ? $this->jwt['body']['aud'][0] : $this->jwt['body']['aud'];
427+
$issuerUrl = $this->jwt['body']['iss'];
428+
$this->registration = $this->db->findRegistrationByIssuer($issuerUrl, $clientId);
408429

409430
if (empty($this->registration)) {
410-
throw new LtiException(static::ERR_MISSING_REGISTRATION);
431+
throw new LtiException($this->getMissingRegistrationErrorMsg($issuerUrl, $clientId));
411432
}
412433

413434
// Check client id.
414-
if ($client_id !== $this->registration->getClientId()) {
435+
if ($clientId !== $this->registration->getClientId()) {
415436
// Client not registered.
416437
throw new LtiException(static::ERR_CLIENT_NOT_REGISTERED);
417438
}

tests/LtiMessageLaunchTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ public function testALaunchFailsIfMissingRegistration()
294294
->once()->andReturn();
295295

296296
$this->expectException(LtiException::class);
297-
$this->expectExceptionMessage(LtiMessageLaunch::ERR_MISSING_REGISTRATION);
297+
$expectedMsg = $this->messageLaunch->getMissingRegistrationErrorMsg($this->issuer['issuer'], $this->issuer['client_id']);
298+
$this->expectExceptionMessage($expectedMsg);
298299

299300
$actual = $this->messageLaunch->validate($payload);
300301
}

0 commit comments

Comments
 (0)