1

PHP 7.4、Windows Server 2012、IIS 8。

我一直在阅读 stackOverflow 和 docusign 自己的文档,但我无法通过 JWT 令牌请求。我试过了:

  • 使用 jwt.io 的说明
  • 手动构建 JWT 请求的说明
  • 使用 SDK 方法 requestJWTApplicationToken
  • 我能想到的 aud 标签的每一个变体
  • 我已验证 account-d.docusign.com、应用程序 ID 和用户 ID
  • 该应用程序已获得同意
  • 我什至从头开始,创建了第二个应用程序,获得了同意,等等......

当我使用 SDK 时,我得到“issuer_not_found”。其他方法,“unsupported_grant_type”。

我整个星期都在研究这件事,但我还没有找到不会引发错误的情况组合。老板每天都在敲打我的笼子。

有人能让我越过这个障碍吗?

issuer_not_found:

// bring in the docusign SDK
require_once("./docusign/vendor/autoload.php");
// bring in the config file provided by the QuickStart on Docusign
require_once("$admin/esign/ds_config.php");

// use the docusign client namespace
use DocuSign\eSign\Client\ApiClient;

// create the SDK client object
$client = new ApiClient();

// get the private key, saved in a file after being copy/pasted from the application 
$rsa_private_key = file_get_contents("$admin/esign/private.key");
// get the client_id a.k.a. app id from the config file provided by the QuickStart on Docusign
$client_id = $GLOBALS['JWT_CONFIG']['ds_client_id'];

// $user_id = $GLOBALS['JWT_CONFIG']['ds_impersonated_user_id'];

// call the SDK api for the application JWT token, lifted from the SDK sample code
$test = $client->requestJWTApplicationToken($client_id, $rsa_private_key);
// $test = $client->requestJWTUserToken($client_id, $user_id, $rsa_private_key);

// display the inevitable error message
echo('<pre>[97616] $test:'  . print_r($test, 1)) . '</pre>';

unsupported_grant_type

use Firebase\JWT\JWT;
use GuzzleHttp\Client;

$header = ["alg"=>"RS256","typ"=>"JWT"];
        
$privateKey = file_get_contents($this->path_admin . "/esign/private.key");

// $publicKey = file_get_contents($this->path_admin . "/esign/public.key");

$expiration = strtotime(date("Y-m-d H:i:s", time()) . " +1 hours"); // subtract 12 hours

$payload = json_encode(array(
    "iss" => $GLOBALS['JWT_CONFIG']['ds_client_id'],
    "aud" => "account-d.docusign.net",
    "iat" => time(),
    "sub" => $GLOBALS['JWT_CONFIG']['ds_impersonated_user_id'],
    "exp" => $expiration,
    "scope" => "signature"
));

$jwt = JWT::encode($payload, $privateKey, 'RS256');

$client = new Client();

$response = $client->request('POST', 'https://account-d.docusign.com/oauth/token', [
    'body' => json_encode([
        'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
        'assertion'  => $jwt
    ])
]);

4

2 回答 2

1

看起来像一个“简单”的配置问题,请检查您是否使用了正确的值(也许说起来容易做起来难)。

首先是故障排除 101:如果最简单的第一次尝试已经给您一个错误,请专注于这个,并且只关注这个,直到它起作用。以防万一这不明显。

对于issuer_not_found

Issuer_not_found: iss(issuer)参数中的集成密钥在当前环境下不可用。这也可能意味着 aud(受众)值和被击中的环境不匹配:例如,在从https://account-d.docusign.com/oauth请求令牌时使用 account.docusign.com 的 aud 值/令牌

对于unsupported_grant_type:您可以在解决第一个错误时解决它 - 开玩笑:

尽可能遵守官方文档,例如使用 JWT 身份验证时,如何解决 invalid_grant 或其他错误?直到它点击。

于 2021-07-09T20:01:27.313 回答
1

最终,issuer_not_found 错误归结为请求正文的“aud”参数和 URL 之间的不匹配:SDK 不查看 POST url 的配置文件,它只是默认为实时 URL,帐户。 docusign.com。要使用 account-d,您必须明确设置该值(我在 SDK 的文档中找不到这一事实。)非常感谢 @hakre 朝正确方向轻推。

于 2021-07-09T21:43:00.387 回答