Skip to content

Commit 9b905cc

Browse files
committed
Allow JWT generation when using the Container credential type
1 parent 244067f commit 9b905cc

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Client.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Nexmo\Client\Credentials\Keypair;
1515
use Nexmo\Client\Credentials\OAuth;
1616
use Nexmo\Client\Credentials\SignatureSecret;
17+
use Nexmo\Client\Exception\Exception;
1718
use Nexmo\Client\Factory\FactoryInterface;
1819
use Nexmo\Client\Factory\MapFactory;
1920
use Nexmo\Client\Response\Response;
@@ -220,8 +221,12 @@ public static function authRequest(RequestInterface $request, Basic $credentials
220221
* @param array $claims
221222
* @return \Lcobucci\JWT\Token
222223
*/
223-
public function generateJwt($claims = []) {
224-
return $this->credentials->generateJwt($claims);
224+
public function generateJwt($claims = [])
225+
{
226+
if (method_exists($this->credentials, "generateJwt")) {
227+
return $this->credentials->generateJwt($claims);
228+
}
229+
throw new Exception(get_class($this->credentials).' does not support JWT generation');
225230
}
226231

227232
/**

src/Client/Credentials/Container.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ public function has($type)
6262
return isset($this->credentials[$type]);
6363
}
6464

65+
public function generateJwt($claims) {
66+
return $this->credentials[Keypair::class]->generateJwt($claims);
67+
}
68+
6569
}

0 commit comments

Comments
 (0)