【发布时间】:2019-08-01 02:37:50
【问题描述】:
我已经下载了JWT Auth sample code
我已经完成并创建了我的集成应用程序并添加了私钥。
修改了 ExampleBase.java 文件以增加日志记录。
OAuth.OAuthToken oAuthToken = null;
System.out.println("Client ID: " + DSConfig.CLIENT_ID);
System.out.println("IUG: " + DSConfig.IMPERSONATED_USER_GUID);
System.out.println("Scopes: " + scopes);
System.out.println("Private Key: " + privateKey);
System.out.println("Token Exp: " + TOKEN_EXPIRATION_IN_SECONDS);
try {
oAuthToken = apiClient.requestJWTUserToken(
DSConfig.CLIENT_ID,
DSConfig.IMPERSONATED_USER_GUID,
scopes,
privateKeyBytes,
TOKEN_EXPIRATION_IN_SECONDS);
} catch (IOException e) {
System.err.println("Error ---IO Exception---");
System.err.println(e.getMessage());
System.err.println(Arrays.toString(e.getStackTrace()));
} catch (IllegalArgumentException e) {
System.err.println("Error while update/fetching token!");
System.err.println(e.getLocalizedMessage());
System.err.println(Arrays.toString(e.getStackTrace()));
} catch (ApiException e) {
System.err.println("API Exception!");
e.printStackTrace();
}
代码输出
Sending an envelope. The envelope includes HTML, Word, and PDF documents. It takes about 15 seconds for DocuSign to process the envelope request...
Token: null
Fetching an access token via JWT grant...
Client ID: cdb3.......2100207
IUG: 7......6
Scopes: [signature]
Private Key: -----BEGIN RSA PRIVATE KEY-----
MIIEogIBAADrH3w0OwPqp0iSLfDgx3kmiCxdnUW6oGUl
llBBsrkaTrPh4DGbFZhS8XiRbwuAFTWkHbLltYP0VoVHmBUhJomPie9+nAfuSWqh
kll5z/ygcGs7Vrn/mZcXTg4VihLzLphlV4FHBfwneQxq/PVIT0U=
-----END RSA PRIVATE KEY-----
Token Exp: 3600
API Exception!
com.docusign.esign.client.ApiException: Error while requesting an access token: POST https://account-d.docusign.com/oauth/token returned a response status of 400 Bad Request
at com.docusign.esign.client.ApiClient.requestJWTUserToken(ApiClient.java:740)
at com.docusign.example.jwt.ExampleBase.updateToken(ExampleBase.java:62)
at com.docusign.example.jwt.ExampleBase.checkToken(ExampleBase.java:40)
at com.docusign.example.jwt.SendEnvelope.sendEnvelope(SendEnvelope.java:54)
at com.docusign.example.jwt.JWTExample.main(JWTExample.java:24)
Done. Continuing...
DocuSign Exception!
Reason: 0
Error Reponse: null
Process finished with exit code 0
我正在调用 DocuSign API 客户端 requestJWTUserToken 并且调用失败并出现 400 Bad Request。可能是 JSON 正文还是我缺少其他内容?
更新(7/31):- 在线阅读后,我发现我们必须将密钥转换为pkcs8格式(Java)。 This 确实帮助我解析密钥并生成 Java 密钥对。仍然遇到生成令牌的问题。
【问题讨论】:
-
示例代码非常糟糕——“APIException”处理程序不会给您任何线索,说明出了什么问题。建议:将
System.err.println("\nDocuSign Exception!");更改为e.printStackTrace();,并使用堆栈回溯更新您的帖子。
标签: java jwt docusignapi