|
2 | 2 |
|
3 | 3 | namespace OpenTokTest; |
4 | 4 |
|
| 5 | +use Firebase\JWT\JWT; |
| 6 | +use Firebase\JWT\Key; |
5 | 7 | use Lcobucci\JWT\Configuration; |
6 | 8 | use Lcobucci\JWT\Token\Plain; |
7 | 9 | use OpenTok\Render; |
@@ -753,41 +755,28 @@ public function testWillCreateLegacyT1WhenRequested(): void |
753 | 755 | public function testWillCreateLegacyT1DirectlyToBypassExpBug(): void |
754 | 756 | { |
755 | 757 | $openTok = new OpenTok('12345678', '0123456789abcdef0123456789abcdef0123456789'); |
756 | | - $token = $openTok->generateToken('1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI', []); |
| 758 | + $token = $openTok->generateToken('1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI', [], true); |
757 | 759 |
|
758 | 760 | $this->assertEquals('T1', substr($token, 0, 2)); |
759 | 761 | } |
760 | 762 |
|
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 | + } |
791 | 780 |
|
792 | 781 | public function testStartsArchive(): void |
793 | 782 | { |
|
0 commit comments