php - I am trying to connect to Docusign through my WebApp and my JWT is failing - "kid" invalid - Stack Overf

I have a web app in PHP, and JS for front-end. I am connecting to Dcusign through the JWT and exchangin

I have a web app in PHP, and JS for front-end. I am connecting to Dcusign through the JWT and exchanging it for an access token, but I keep getting this error:

Decoding JWT did not work

UnexpectedValueException: "kid" invalid, unable to lookup correct key in /html/htdocs/mrt_dghehe/vendor/firebase/php-jwt/src/JWT.php:477

The code for JWT looks like this:

$now = time();
$payload = [
    'iss' => $clientId,
    'sub' => $apiUserId,
    'aud' => 'account-d.docusign',
    'scope' => 'signature impersonation',
    'iat' => $now,
    'exp' => $now + 3600 // 1 hour expiration
];
$privateKey = file_get_contents($privateKeyFilePath);
$jwt = JWT::encode($payload, $privateKey, 'RS256', $keypairID); //kid
$publicKey = file_get_contents('publicKey.key');

try
{
    $decodedJWT = JWT::decode($jwt,$publicKey);
    print_r($decodedJWT);
    echo "This is the decoded JWT";
}
catch(Exception $e)
{
    echo "Decoding JWT did not work";
    print($e);

Is the kid the equivalent of the Docusign Keypair ID? I am manually transmitting it when encoding the JWT but I do not even know if it's the right approach.

I have a web app in PHP, and JS for front-end. I am connecting to Dcusign through the JWT and exchanging it for an access token, but I keep getting this error:

Decoding JWT did not work

UnexpectedValueException: "kid" invalid, unable to lookup correct key in /html/htdocs/mrt_dghehe/vendor/firebase/php-jwt/src/JWT.php:477

The code for JWT looks like this:

$now = time();
$payload = [
    'iss' => $clientId,
    'sub' => $apiUserId,
    'aud' => 'account-d.docusign',
    'scope' => 'signature impersonation',
    'iat' => $now,
    'exp' => $now + 3600 // 1 hour expiration
];
$privateKey = file_get_contents($privateKeyFilePath);
$jwt = JWT::encode($payload, $privateKey, 'RS256', $keypairID); //kid
$publicKey = file_get_contents('publicKey.key');

try
{
    $decodedJWT = JWT::decode($jwt,$publicKey);
    print_r($decodedJWT);
    echo "This is the decoded JWT";
}
catch(Exception $e)
{
    echo "Decoding JWT did not work";
    print($e);

Is the kid the equivalent of the Docusign Keypair ID? I am manually transmitting it when encoding the JWT but I do not even know if it's the right approach.

Share Improve this question edited Mar 7 at 9:49 ADyson 62.2k16 gold badges79 silver badges92 bronze badges Recognized by PHP Collective asked Mar 7 at 9:19 potatopotato 791 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You have to pass an Object of type Key to the decode-method, not the textual key itself.

$publicKey = new Key(file_get_contents('publicKey.key'), 'RS256');
$decodedJWT = JWT::decode($jwt, $publicKey);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744939403a4602229.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信