Skip to content

Commit 3f10580

Browse files
committed
Changed generateToken back to returning T1 tokens due to auth bug in the API
1 parent d305b4e commit 3f10580

File tree

2 files changed

+71
-48
lines changed

2 files changed

+71
-48
lines changed

src/OpenTok/OpenTok.php

+30-29
Original file line numberDiff line numberDiff line change
@@ -120,45 +120,46 @@ public function __construct($apiKey, $apiSecret, $options = array())
120120
*/
121121
public function generateToken(string $sessionId, array $options = array(), bool $legacy = false): string
122122
{
123-
if ($legacy) {
124-
return $this->returnLegacyToken($sessionId, $options);
125-
}
123+
// Note, JWT generation disabled due to a backend bug regarding `exp` claims being mandatory - CRT
124+
// if ($legacy) {
125+
return $this->returnLegacyToken($sessionId, $options);
126+
// }
126127

127-
$issuedAt = new \DateTimeImmutable('@' . time());
128+
// $issuedAt = new \DateTimeImmutable('@' . time());
128129

129-
$defaults = [
130-
'session_id' => $sessionId,
131-
'role' => Role::PUBLISHER,
132-
'expireTime' => null,
133-
'initial_layout_list' => [''],
134-
'ist' => 'project',
135-
'nonce' => mt_rand(),
136-
'scope' => 'session.connect'
137-
];
130+
// $defaults = [
131+
// 'session_id' => $sessionId,
132+
// 'role' => Role::PUBLISHER,
133+
// 'expireTime' => null,
134+
// 'initial_layout_list' => [''],
135+
// 'ist' => 'project',
136+
// 'nonce' => mt_rand(),
137+
// 'scope' => 'session.connect'
138+
// ];
138139

139-
$options = array_merge($defaults, array_intersect_key($options, $defaults));
140+
// $options = array_merge($defaults, array_intersect_key($options, $defaults));
140141

141-
$builder = new Builder(new JoseEncoder(), ChainedFormatter::default());
142-
$builder = $builder->issuedBy($this->apiKey);
142+
// $builder = new Builder(new JoseEncoder(), ChainedFormatter::default());
143+
// $builder = $builder->issuedBy($this->apiKey);
143144

144-
if ($options['expireTime']) {
145-
$expiry = new \DateTimeImmutable('@' . $options['expireTime']);
146-
$builder = $builder->expiresAt($expiry);
147-
}
145+
// if ($options['expireTime']) {
146+
// $expiry = new \DateTimeImmutable('@' . $options['expireTime']);
147+
// $builder = $builder->expiresAt($expiry);
148+
// }
148149

149-
unset($options['expireTime']);
150+
// unset($options['expireTime']);
150151

151-
$builder = $builder->issuedAt($issuedAt);
152-
$builder = $builder->canOnlyBeUsedAfter($issuedAt);
153-
$builder = $builder->identifiedBy(bin2hex(random_bytes(16)));
152+
// $builder = $builder->issuedAt($issuedAt);
153+
// $builder = $builder->canOnlyBeUsedAfter($issuedAt);
154+
// $builder = $builder->identifiedBy(bin2hex(random_bytes(16)));
154155

155-
foreach ($options as $key => $value) {
156-
$builder = $builder->withClaim($key, $value);
157-
}
156+
// foreach ($options as $key => $value) {
157+
// $builder = $builder->withClaim($key, $value);
158+
// }
158159

159-
$token = $builder->getToken(new \Lcobucci\JWT\Signer\Hmac\Sha256(), InMemory::plainText($this->apiSecret));
160+
// $token = $builder->getToken(new \Lcobucci\JWT\Signer\Hmac\Sha256(), InMemory::plainText($this->apiSecret));
160161

161-
return $token->toString();
162+
// return $token->toString();
162163
}
163164

164165
private function returnLegacyToken(string $sessionId, array $options = []): string

tests/OpenTokTest/OpenTokTest.php

+41-19
Original file line numberDiff line numberDiff line change
@@ -742,31 +742,53 @@ public function testFailsWhenGeneratingTokenUsingInvalidRole(): void
742742
$token = $this->opentok->generateToken('SESSIONID', array('role' => 'notarole'), true);
743743
}
744744

745-
public function testWillCreateJwt(): void
745+
public function testWillCreateLegacyT1WhenRequested(): void
746746
{
747-
$openTok = new OpenTok('my-api-key', 'my-super-long-and-cool-api-secret');
748-
$token = $openTok->generateToken('some-token-value');
747+
$openTok = new OpenTok('12345678', '0123456789abcdef0123456789abcdef0123456789');
748+
$token = $openTok->generateToken('1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI', [], true);
749749

750-
$config = Configuration::forSymmetricSigner(
751-
new \Lcobucci\JWT\Signer\Hmac\Sha256(),
752-
\Lcobucci\JWT\Signer\Key\InMemory::plainText('my-super-long-and-cool-api-secret')
753-
);
754-
755-
$token = $config->parser()->parse($token);
756-
$this->assertInstanceOf(Plain::class, $token);
750+
$this->assertEquals('T1', substr($token, 0, 2));
751+
}
757752

758-
$this->assertTrue($config->validator()->validate($token, new \Lcobucci\JWT\Validation\Constraint\SignedWith(
759-
$config->signer(),
760-
$config->signingKey()
761-
)));
753+
public function testWillCreateLegacyT1DirectlyToBypassExpBug(): void
754+
{
755+
$openTok = new OpenTok('12345678', '0123456789abcdef0123456789abcdef0123456789');
756+
$token = $openTok->generateToken('1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI', []);
762757

763-
$this->assertEquals('my-api-key', $token->claims()->get('iss'));
764-
$this->assertEquals('some-token-value', $token->claims()->get('session_id'));
765-
$this->assertEquals('publisher', $token->claims()->get('role'));
766-
$this->assertEquals('project', $token->claims()->get('ist'));
767-
$this->assertEquals('session.connect', $token->claims()->get('scope'));
758+
$this->assertEquals('T1', substr($token, 0, 2));
768759
}
769760

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+
// }
791+
770792
public function testStartsArchive(): void
771793
{
772794
// Arrange

0 commit comments

Comments
 (0)