Skip to content

Commit 8288d8a

Browse files
committed
Test firebase JWT
1 parent 8d93b2a commit 8288d8a

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

tests/OpenTokTest/OpenTokTest.php

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace OpenTokTest;
44

5+
use Firebase\JWT\JWT;
6+
use Firebase\JWT\Key;
57
use Lcobucci\JWT\Configuration;
68
use Lcobucci\JWT\Token\Plain;
79
use OpenTok\Render;
@@ -753,41 +755,28 @@ public function testWillCreateLegacyT1WhenRequested(): void
753755
public function testWillCreateLegacyT1DirectlyToBypassExpBug(): void
754756
{
755757
$openTok = new OpenTok('12345678', '0123456789abcdef0123456789abcdef0123456789');
756-
$token = $openTok->generateToken('1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI', []);
758+
$token = $openTok->generateToken('1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI', [], true);
757759

758760
$this->assertEquals('T1', substr($token, 0, 2));
759761
}
760762

761-
/**
762-
* Makes sure that a JWT is generated for the client-side token
763-
*
764-
* Currently disabled due to the backend requiring an `exp` claim, which was
765-
* not required on T1s. Uncomment when the backend is fixed. - CRT
766-
*/
767-
// public function testWillCreateJwt(): void
768-
// {
769-
// $openTok = new OpenTok('my-api-key', 'my-super-long-and-cool-api-secret');
770-
// $token = $openTok->generateToken('some-token-value');
771-
772-
// $config = Configuration::forSymmetricSigner(
773-
// new \Lcobucci\JWT\Signer\Hmac\Sha256(),
774-
// \Lcobucci\JWT\Signer\Key\InMemory::plainText('my-super-long-and-cool-api-secret')
775-
// );
776-
777-
// $token = $config->parser()->parse($token);
778-
// $this->assertInstanceOf(Plain::class, $token);
779-
780-
// $this->assertTrue($config->validator()->validate($token, new \Lcobucci\JWT\Validation\Constraint\SignedWith(
781-
// $config->signer(),
782-
// $config->signingKey()
783-
// )));
784-
785-
// $this->assertEquals('my-api-key', $token->claims()->get('iss'));
786-
// $this->assertEquals('some-token-value', $token->claims()->get('session_id'));
787-
// $this->assertEquals('publisher', $token->claims()->get('role'));
788-
// $this->assertEquals('project', $token->claims()->get('ist'));
789-
// $this->assertEquals('session.connect', $token->claims()->get('scope'));
790-
// }
763+
public function testWillGenerateSha256Token(): void
764+
{
765+
$openTok = new OpenTok('12345678', '0123456789abcdef0123456789abcdef0123456789');
766+
$token = $openTok->generateToken('1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI');
767+
768+
$this->assertNotEquals('T1', substr($token, 0, 2));
769+
770+
$decoded = JWT::decode($token, new Key('0123456789abcdef0123456789abcdef0123456789', 'HS256'));
771+
$decodedArray = (array) $decoded;
772+
773+
$this->assertEquals('12345678', $decodedArray['iss']);
774+
$this->assertEquals('1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI', $decodedArray['session_id']);
775+
$this->assertEquals('project', $decodedArray['ist']);
776+
$this->assertEquals('session.connect', $decodedArray['scope']);
777+
$this->assertEquals('publisher', $decodedArray['role']);
778+
779+
}
791780

792781
public function testStartsArchive(): void
793782
{

0 commit comments

Comments
 (0)