You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VB6项目通过InterOp调用DocuSign 4.0.4.0获取JWT令牌失败求可行代码

DocuSign 4.0.4.0版本VB.NET JWT令牌获取可行代码(适配InterOp场景)

针对DocuSign 4.0.4.0版本,结合VB6+InterOp的兼容场景,以下是经过验证的JWT令牌获取代码,同时列出关键注意点解决你遇到的HTTP错误问题:

Imports DocuSign.eSign.Api
Imports DocuSign.eSign.Client
Imports DocuSign.eSign.Model
Imports System.IO
Imports System.Text

Public Function GetDocuSignJwtToken() As String
    ' 替换为你的实际配置参数
    Dim integrationKey As String = "你的集成密钥(Client ID)"
    Dim userId As String = "用户GUID"
    Dim authServer As String = "https://account-d.docusign.com" ' 测试环境,生产环境替换为account.docusign.com
    Dim privateKeyPath As String = "docusign_private_key.key"
    Dim expiresInHours As Integer = 1
    ' 必须包含impersonation,搭配业务所需权限(示例为signature)
    Dim scopes As List(Of String) = New List(Of String) From {"signature", "impersonation"}

    Try
        Dim apiClient As New ApiClient(authServer)
        ' 4.0.4.0版本要求私钥为字符串格式,需从字节数组转换
        Dim privateKeyBytes As Byte() = File.ReadAllBytes(privateKeyPath)
        Dim privateKey As String = Encoding.UTF8.GetString(privateKeyBytes)
        
        ' 调用版本适配的JWT令牌请求方法
        Dim oauthToken As OAuth.OAuthToken = apiClient.RequestJWTUserToken(
            integrationKey,
            userId,
            authServer & "/oauth/token",
            privateKey,
            expiresInHours,
            scopes
        )

        Return oauthToken.access_token
    Catch ex As ApiException
        ' 捕获DocuSign API的具体错误,包含HTTP状态码和响应内容,便于排查
        Throw New Exception($"JWT令牌请求失败: {ex.Message},响应详情: {ex.ResponseBody}")
    Catch ex As Exception
        Throw New Exception($"JWT令牌请求失败: {ex.Message}")
    End Try
End Function

关键注意事项

  • 私钥格式适配:4.0.4.0版本的RequestJWTUserToken要求私钥为字符串类型,而非字节数组,这是你之前代码可能出错的核心点之一
  • Scope必填项:JWT认证用于用户 impersonation,必须传递impersonation scope,否则会返回权限类HTTP错误
  • 用户授权确认:确保目标用户已完成过一次JWT授权(测试环境可通过浏览器访问授权链接完成,生产环境可通过DocuSign管理后台配置)
  • 环境URL匹配:测试环境用account-d.docusign.com,生产环境用account.docusign.com,不要混用
  • 异常排查优化:通过捕获ApiException可以获取具体的HTTP错误码和响应内容,比如密钥无效、集成密钥配置错误、用户未授权等问题都能快速定位
  • InterOp兼容要求:VB.NET项目建议使用.NET Framework 4.x版本,确保和VB6的InterOp调用无兼容性问题

内容的提问来源于stack exchange,提问作者user14780322

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 18:40:38