首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Rest Api从Docusing生成访问令牌时出错

问使用Rest Api从Docusing生成访问令牌时出错
EN

Stack Overflow用户
提问于 2021-03-30 18:47:01
回答 1查看 38关注 0票数 0

我使用下面的代码获取访问令牌,

代码语言:javascript
复制
       Dim a As String = header & "." & body & "." & sign
       System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
        ServicePointManager.Expect100Continue = True
        Dim request As WebRequest =
      WebRequest.Create("https://account-d.docusign.com/oauth/token?grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=" & a & "")
        request.Method = "POST"

        request.Headers.Add("X-DocuSign-Authentication", "{ ""Username"":""" & odjDTRep.Rows(0)("UserName").ToString() & """,  ""Password"":""" & odjDTRep.Rows(0)("Password").ToString() & """,  ""IntegratorKey"":""" & odjDTRep.Rows(0)("iss_Int_Key").ToString() & """ }")
        Dim response As WebResponse = request.GetResponse() ' Here i get error
        Dim dataStream As Stream = response.GetResponseStream()
        Dim reader As New StreamReader(dataStream)
        Dim responseFromServer As String = reader.ReadToEnd()
        reader.Close()
        response.Close()

错误是“请求已中止:无法创建SSL/TLS安全通道”。

EN

回答 1

Stack Overflow用户

发布于 2021-03-31 06:54:06

您混合了不同的授权技术和类型。我将假设您想要使用JWT,因为您将grant-type:jwt作为您试图对其进行POST调用的URL的一部分。要使用JWT,您确实需要X-DocuSign-Authentication头,并且您当然不需要在代码中包含密码。你需要obtain consent一次,然后你需要构建你的Javascript Web令牌,它看起来像这样:

代码语言:javascript
复制
{
  "iss": "5c2b8d7e-xxxx-xxxx-xxxx-cda8a50dd73f",
  "sub": "464f7988-xxxx-xxxx-xxxx-781ee556ab7a",
  "aud": "account-d.docusign.com",
  "iat": 1598383123,
  "exp": 1598390123,
  "scope": "signature impersonation"
}

但是,您还需要一个RSA Keypair,我建议您遵循上面链接的the article,看看如何获取和使用它。

您还可以使用具有JWT支持并且应该能够在VB.NET项目中使用的C# SDK。下面是VB.NET代码:

代码语言:javascript
复制
  Sub Main()
    Dim integratorKey As String = "9e1d5046-8888-430d-9b48-xxxxxxx"
    '//Demo Environment
    Dim host As String = "https://demo.docusign.net/restapi"
    Dim userId As String = "dcce8b59-19ec-4273-b283-xxxxxxxx" ' //geoffp.dstest@gmail.com
    Dim scopes As List(Of String) = New List(Of String)
    scopes.Add("signature")
    scopes.Add("impersonation")
    Dim oauthBasePath As String = "account-d.docusign.com"
    Dim RSA_Key_File As String = "C:\Users\geoff.pfander\Box Sync\geoffp\OAuth\DemoPrivate Key.txt"
    Dim privateKeyBytes() As Byte = System.IO.File.ReadAllBytes(RSA_Key_File) ' // Create a Byte array
    Dim expiresInHours As Integer = 1
    Dim accountId As String = String.Empty
    Dim apiClient As DocuSign.eSign.Client.ApiClient = New DocuSign.eSign.Client.ApiClient(host)
    Dim tokenInfo As DocuSign.eSign.Client.Auth.OAuth.OAuthToken = apiClient.RequestJWTUserToken(integratorKey, userId, oauthBasePath, privateKeyBytes, expiresInHours, scopes)
    Console.WriteLine(tokenInfo.access_token)
    Console.ReadLine()
  End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66869535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档