Skip to content

Commit

Permalink
Merge pull request #29 from oat-sa/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ekkinox authored May 10, 2020
2 parents 12b665b + 94eaab1 commit 4034a6a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

1.2.0
-----

* Added `getOidcState()` method to `LtiLaunchRequestValidationResult`

1.1.0
-----

Expand Down
12 changes: 8 additions & 4 deletions doc/message/oidc-resource-link-launch.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,15 @@ if (!$result->hasError()) {
echo $result->getRegistration()->getIdentifier();

// And to the LTI message components
echo $result->getLtiMessage()->getVersion(); // '1.3.0'
echo $result->getLtiMessage()->getContext()->getId(); // 'contextId'
echo $result->getLtiMessage()->getClaim('myCustomClaim'); // 'myCustomValue'
echo $result->getLtiMessage()->getUserIdentity(); // given by the platform at OIDC authentication
echo $result->getLtiMessage()->getVersion(); // '1.3.0'
echo $result->getLtiMessage()->getContext()->getId(); // 'contextId'
echo $result->getLtiMessage()->getClaim('myCustomClaim'); // 'myCustomValue'
echo $result->getLtiMessage()->getUserIdentity(); // given by the platform at OIDC authentication

// If needed, you can also access the OIDC state components
echo $result->getOidcState()->getToken()->__toString(); // state JWT
echo $result->getOidcState()->getToken()->getClaim('jti'); // state JWT id

// If needed, you can also access the validation successes
foreach ($result->getSuccesses() as $success) {
echo $success;
Expand Down
11 changes: 11 additions & 0 deletions src/Launch/Validator/LtiLaunchRequestValidationResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OAT\Library\Lti1p3Core\Launch\Validator;

use OAT\Library\Lti1p3Core\Message\LtiMessageInterface;
use OAT\Library\Lti1p3Core\Message\MessageInterface;
use OAT\Library\Lti1p3Core\Registration\RegistrationInterface;

class LtiLaunchRequestValidationResult
Expand All @@ -33,6 +34,9 @@ class LtiLaunchRequestValidationResult
/** @var LtiMessageInterface|null */
private $ltiMessage;

/** @var MessageInterface|null */
private $oidcState;

/** @var string[] */
private $successes;

Expand All @@ -42,11 +46,13 @@ class LtiLaunchRequestValidationResult
public function __construct(
RegistrationInterface $registration = null,
LtiMessageInterface $ltiMessage = null,
MessageInterface $oidcState = null,
array $successes = [],
string $error = null
) {
$this->registration = $registration;
$this->ltiMessage = $ltiMessage;
$this->oidcState = $oidcState;
$this->successes = $successes;
$this->error = $error;
}
Expand All @@ -61,6 +67,11 @@ public function getLtiMessage(): ?LtiMessageInterface
return $this->ltiMessage;
}

public function getOidcState(): ?MessageInterface
{
return $this->oidcState;
}

public function addSuccess(string $success): self
{
$this->successes[] = $success;
Expand Down
4 changes: 2 additions & 2 deletions src/Launch/Validator/LtiLaunchRequestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public function validate(ServerRequestInterface $request): LtiLaunchRequestValid
->validateStateSignature($registration, $oidcState)
->validateStateExpiry($oidcState);

return new LtiLaunchRequestValidationResult($registration, $ltiMessage, $this->successes);
return new LtiLaunchRequestValidationResult($registration, $ltiMessage, $oidcState, $this->successes);

} catch (Throwable $exception) {
return new LtiLaunchRequestValidationResult(null, null, $this->successes, $exception->getMessage());
return new LtiLaunchRequestValidationResult(null, null, null, $this->successes, $exception->getMessage());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Security/Jwks/Fetcher/JwksFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function fetchJwksDataFromUrl(string $jwksUrl): ?array

$this->logger->error($message);

throw new LtiException($message,$exception->getCode(), $exception);
throw new LtiException($message, $exception->getCode(), $exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use OAT\Library\Lti1p3Core\Launch\Validator\LtiLaunchRequestValidationResult;
use OAT\Library\Lti1p3Core\Message\LtiMessageInterface;
use OAT\Library\Lti1p3Core\Message\MessageInterface;
use OAT\Library\Lti1p3Core\Registration\RegistrationInterface;
use PHPUnit\Framework\TestCase;

Expand All @@ -47,6 +48,15 @@ public function testGetLtiMessage(): void
$this->assertEquals($ltiMessageMock, $subject->getLtiMessage());
}

public function testGetOidcState(): void
{
$oidcStateMock = $this->createMock(MessageInterface::class);

$subject = new LtiLaunchRequestValidationResult(null, null, $oidcStateMock);

$this->assertEquals($oidcStateMock, $subject->getOidcState());
}

public function testBehavior(): void
{
$subject = new LtiLaunchRequestValidationResult();
Expand Down

0 comments on commit 4034a6a

Please sign in to comment.