我在尝试从 DocuSign 检索 JWT 令牌时遇到问题,到目前为止,这是我已完成的代码片段(使用 DEVELOPER SANDBOX 帐户):// Developer exmple$header = [ 'typ' => 'JWT', 'alg' => 'RS256',];$time = time();$body = [ // Integration key provded by DocuSign at Admin > API and Keys > Apps. 'iss' => '[Integration key]', // User ID provded by DocuSign at Admin > API and Keys. 'sub' => '[User ID]', 'iat' => $time, 'exp' => strtotime( '+45 minutes', $time ), 'aud' => 'account-d.docusign.com', 'scope' => 'signature impersonation',];// RSA Private key provided by DocuSign// When integration APP was created$rsa_key = '-----BEGIN RSA PRIVATE KEY----- [.........]';// Base64 + URL Encoding$header = urlencode( base64_encode( json_encode( $header ) ) );$body = urlencode( base64_encode( json_encode( $body ) ) );// JWT signature created using Firebase\JWT\JWT package$signature = JWT::encode( $header . '.' . $body, $rsa_key, 'RS256');// Get request using Curl (10quality/php-curl package)$response = curl_request( 'https://account-d.docusign.com/oauth/token', 'POST', [ 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer', 'assertion' => $header . '.' . $body . '.' . $signature, ]);// Process responseif ( $response ) { $response = json_decode( $response ); if ( isset( $response->error ) ) throw new Exception( 'DocuSign error: ' . $response->error ); var_dump( $response );}这是我遵循的指南: https: //developers.docusign.com/esign-rest-api/guides/authentication/oauth2-jsonwebtoken根据本指南,抛出的错误表明 JWT 未正确创建,尽管我已多次检查我的代码并且它遵循指南中描述的所有内容。我有点卡住了,我对我的代码有什么问题一无所知,我什至做了逆向工程来验证编码是否正确。有没有人以前使用过 DocuSign JWT 或者知道我可能做错了什么?
2 回答
隔江千里
TA贡献1906条经验 获得超10个赞
我相信你想更换你的台词:
$header = urlencode( base64_encode( json_encode( $header ) ) );
$body = urlencode( base64_encode( json_encode( $body ) ) );
和
$header = str_replace('=', '', strtr(base64_encode($header ), '+/', '-_'));
$body = str_replace('=', '', strtr(base64_encode($body), '+/', '-_'));
与您的签名相同:
$signature = str_replace('=', '', strtr(base64_encode($signature), '+/', '-_'));
- 2 回答
- 0 关注
- 136 浏览
添加回答
举报
0/150
提交
取消