Skip to content

Commit f80f3b8

Browse files
committed
When making a voice call, only the Keypair auth is required
This commit adds `Keypair` to the list of valid credential types and fixes a bug where we call `->get()` before generating the JWT when `$this->credentials` is already the Keypair credential type
1 parent 0fe2b7e commit f80f3b8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function __construct(CredentialsInterface $credentials, $options = array(
7777
$this->setHttpClient($client);
7878

7979
//make sure we know how to use the credentials
80-
if(!($credentials instanceof Container) && !($credentials instanceof Basic) && !($credentials instanceof SignatureSecret) && !($credentials instanceof OAuth)){
80+
if(!($credentials instanceof Container) && !($credentials instanceof Basic) && !($credentials instanceof SignatureSecret) && !($credentials instanceof OAuth) && !($credentials instanceof Keypair)){
8181
throw new \RuntimeException('unknown credentials type: ' . get_class($credentials));
8282
}
8383

@@ -298,7 +298,7 @@ public function send(\Psr\Http\Message\RequestInterface $request)
298298
$request = self::authRequest($request, $this->credentials->get(Basic::class));
299299
}
300300
} elseif($this->credentials instanceof Keypair){
301-
$request = $request->withHeader('Authorization', 'Bearer ' . $this->credentials->get(Keypair::class)->generateJwt());
301+
$request = $request->withHeader('Authorization', 'Bearer ' . $this->credentials->generateJwt());
302302
} elseif($this->credentials instanceof SignatureSecret){
303303
$request = self::signRequest($request, $this->credentials);
304304
} elseif($this->credentials instanceof Basic){

test/ClientTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ public function testOAuthCredentials()
122122
$this->markTestIncomplete('not yet implemented');
123123
}
124124

125+
public function testKeypairCredentials()
126+
{
127+
$client = new Client($this->key_credentials, [], $this->http);
128+
$request = $this->getRequest('json');
129+
130+
$client->send($request);
131+
132+
$request = $this->http->getRequests()[0];
133+
$this->assertEmpty($request->getUri()->getQuery());
134+
$auth = $request->getHeaderLine('Authorization');
135+
$this->assertStringStartsWith('Bearer ', $auth);
136+
$this->markTestIncomplete('Has correct format, but not tested as output of JWT generation');
137+
}
138+
125139
public function testSettingBaseUrl()
126140
{
127141
$client = new Client(new Basic('key', 'secret'), [

0 commit comments

Comments
 (0)