Docusign API Auth - 使用哪个
Docusign API Auth - which to use
刚刚开始在我的网站上实施 Docusign。 (.NET VB.NET)
需要确保我选择了正确的授权类型来访问 API。
用户将登录网站并将 select 文档发送给指定的收件人。
公司将拥有一个用于所有文档签名的整体 DocuSign 帐户。用户将没有单独的 DocuSign 帐户,但他们将有单独的网站登录凭据。
我认为这是 JWT 的情况,但不确定。有没有更简单的方法来授权每个签名?
感谢任何想法。
对我来说听起来像是智威汤逊。另请注意以下事项:
JSON Web 令牌 (JWT) 身份验证使开发人员能够代表某些用户请求令牌,而无需该用户登录。这意味着除了第一次,当用户必须同意时,无需网络 UI 即可获取令牌。 JWT 令牌用于特定帐户中的特定用户,它是用于唯一标识用户的用户 ID 的 GUID。如果您有多个帐户,则必须确保为正确的帐户使用正确的用户 ID。另请注意,DocuSign 中的用户具有不同的权限配置文件,并且可能具有也可能不具有执行 API 尝试执行的操作所需的访问权限。
JWT 可能不是允许许多不同用户使用他们自己的 DocuSign 登录名发送信封的 Web 应用程序的最佳选择。对于这些场景,授权码授予是更合适的模型,因为它要求最终用户在生成用于访问 API 的令牌之前使用其凭据登录 DocuSign。
我终于可以使用 vb.net 了。显然没有适合我们 vb 开发人员的文档,所以如果它可能对其他人有帮助,我 post 我的代码在这里。流程从过程“Button1_Click”开始......它将文档发送给收件人进行签名,并将 returns Docusign 结果响应发送到文本框“txtResult”。这基于转换为 vb.net 的 C# 文档中的演示过程。私钥是从本地 .txt 文件中读取的,该文件包含包含 -----BEGIN PRIVATE KEY---- 和 ----END PRIVATE KEY---- 标志的密钥。
Imports System.IO
Imports System.Net
Imports System.Text
Imports DocuSign.eSign.Api
Imports DocuSign.eSign.Client
Imports DocuSign.eSign.Client.Auth
Imports DocuSign.eSign.Model
Partial Class DocusignTest
Inherits System.Web.UI.Page
'---------------------------------------
'Process Begins With This Button Click....
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
txtResult.Text = SendEnvelopeViaEmail("recip1@wherever.com",
"Recip1 Name",
"recip2@anotherplace.com",
"Recip2 Name",
GetaccessToken(),
"https://demo.docusign.net/restapi",
"Your Account ID",
"C:\Users\Dotne\Downloads\World_Wide_Corp_Battle_Plan_Trafalgar.docx",
"C:\Users\Dotne\Downloads\World_Wide_Corp_lorem.pdf",
"sent")
End Sub
'---------------------------------------
Public Shared Function SendEnvelopeViaEmail(ByVal signerEmail As String,
ByVal signerName As String,
ByVal ccEmail As String,
ByVal ccName As String,
ByVal accessToken As String,
ByVal basePath As String,
ByVal accountId As String,
ByVal docDocx As String,
ByVal docPdf As String,
ByVal envStatus As String) As String
'/ <summary>
'/ Creates an envelope that would include two documents and add a signer and cc recipients to be notified via email
'/ </summary>
'/ <param name="signerEmail">Email address for the signer</param>
'/ <param name="signerName">Full name of the signer</param>
'/ <param name="ccEmail">Email address for the cc recipient</param>
'/ <param name="ccName">Name of the cc recipient</param>
'/ <param name="accessToken">Access Token for API call (OAuth)</param>
'/ <param name="basePath">BasePath for API calls (URI)</param>
'/ <param name="accountId">The DocuSign Account ID (GUID or short version) for which the APIs call would be made</param>
'/ <param name="docPdf">String of bytes representing the document (pdf)</param>
'/ <param name="docDocx">String of bytes representing the Word document (docx)</param>
'/ <param name="envStatus">Status to set the envelope to</param>
'/ <returns>EnvelopeId for the new envelope</returns>
Dim env As EnvelopeDefinition = MakeEnvelope(signerEmail, signerName, ccEmail, ccName, docDocx, docPdf, envStatus)
Dim apiClient As ApiClient = New ApiClient(basePath)
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " & accessToken)
Dim envelopesApi As EnvelopesApi = New EnvelopesApi(apiClient)
Dim results As EnvelopeSummary = envelopesApi.CreateEnvelope(accountId, env)
Return results.EnvelopeId
End Function
'---------------------------------------
Private Shared Function MakeEnvelope(ByVal signerEmail As String, ByVal signerName As String, ByVal ccEmail As String, ByVal ccName As String, ByVal docDocx As String, ByVal docPdf As String, ByVal envStatus As String) As EnvelopeDefinition
' Data for this method
' Config.docDocx
' Config.docPdf
' RequestItemsService.Status -- the envelope status ('created' or 'sent')
' document 1 (html) has tag **signature_1**
' document 2 (docx) has tag /sn1/
' document 3 (pdf) has tag /sn1/
'
' The envelope has two recipients.
' recipient 1 - signer
' recipient 2 - cc
' The envelope will be sent first to the signer.
' After it is signed, a copy is sent to the cc person.
' read files from a local directory
' The reads could raise an exception if the file is not available!
Dim document1 = Encoding.UTF8.GetBytes(" <!DOCTYPE html>\n" &
" <html>" &
" <head>" &
" <meta charset='UTF-8'>" &
" </head>" &
" <body style=""font-family:sans-serif;margin-left:2em;"">" &
" <h1 style=""font-family: 'Trebuchet MS', Helvetica, sans-serif;" &
" color: darkblue;margin-bottom: 0;"">World Wide Corp</h1>" &
" <h2 style=""font-family: 'Trebuchet MS', Helvetica, sans-serif;" &
" margin-top: 0px;margin-bottom: 3.5em;font-size: 1em;" &
" color: darkblue;"">Order Processing Division</h2>" &
" <h4>Ordered by " & signerName & "</h4>" &
" <p style=""margin-top: 0em; margin-bottom:0em;"">Email: " & signerEmail & "</p>" &
" <p style=""margin-top:0em; margin-bottom:0em;"">Copy to: " & ccName & ", " & ccEmail & "</p>" &
" <p style=""margin-top:3em;"">" &
" Candy bonbon pastry jujubes lollipop wafer biscuit biscuit. Topping brownie sesame snaps sweet roll pie. Croissant danish biscuit soufflé caramels jujubes jelly. Dragée danish caramels lemon drops dragée. Gummi bears cupcake biscuit tiramisu sugar plum pastry. Dragée gummies applicake pudding liquorice. Donut jujubes oat cake jelly-o. Dessert bear claw chocolate cake gummies lollipop sugar plum ice cream gummies cheesecake." &
" </p>" &
" <!-- Note the anchor tag for the signature field Is in white. -->" &
" <h3 style=""margin-top:3em;"">Agreed: <span style=""color:white;"">**signature_1**/</span></h3>" &
" </body>" &
" </html>")
Dim doc2DocxBytes As String = Convert.ToBase64String(System.IO.File.ReadAllBytes(docDocx))
Dim doc3PdfBytes As String = Convert.ToBase64String(System.IO.File.ReadAllBytes(docPdf))
' create the envelope definition
Dim env As EnvelopeDefinition = New EnvelopeDefinition()
env.EmailSubject = "Please sign this document set"
' Create document objects, one per document
Dim doc1 As Document = New Document()
Dim b64 As String = Convert.ToBase64String(document1) '(signerEmail, signerName, ccEmail, ccName)
With doc1
.DocumentBase64 = b64
.Name = "Order acknowledgement" ' can be different from actual file name
.FileExtension = "html" ' Source data format. Signed docs are always pdf.
.DocumentId = "1" ' a label used to reference the doc
End With
Dim doc2 As Document = New Document
With doc2
.DocumentBase64 = doc2DocxBytes
.Name = "Battle Plan"
.FileExtension = "docx"
.DocumentId = "2"
End With
Dim doc3 As Document = New Document
With doc3
.DocumentBase64 = doc3PdfBytes
.Name = "Lorem Ipsum"
.FileExtension = "pdf"
.DocumentId = "3"
End With
' The order in the docs array determines the order in the envelope
Dim DocList As New List(Of Document)
DocList.Add(doc1)
DocList.Add(doc2)
DocList.Add(doc3)
env.Documents = DocList
' create a signer recipient to sign the document, identified by name and email
Dim signer1 As Signer = New Signer
With signer1
.Email = signerEmail
.Name = signerName
.RecipientId = "1"
.RoutingOrder = "1"
End With
' routingOrder (lower means earlier) determines the order of deliveries
' to the recipients. Parallel routing order is supported by using the
' same integer as the order for two or more recipients.
' create a cc recipient to receive a copy of the documents, identified by name and email
Dim CC1 As CarbonCopy = New CarbonCopy
With CC1
.Email = ccEmail
.Name = ccName
.RecipientId = "2"
.RoutingOrder = "2"
End With
' Create signHere fields (also known as tabs) on the documents,
' We're using anchor (autoPlace) positioning
'
' The DocuSign platform searches throughout your envelope's
' documents for matching anchor strings. So the
' signHere2 tab will be used in both document 2 and 3 since they
' use the same anchor string for their "signer 1" tabs.
Dim signHere1 As SignHere = New SignHere
With signHere1
.AnchorString = "**signature_1**"
.AnchorUnits = "pixels"
.AnchorYOffset = "10"
.AnchorXOffset = "20"
End With
Dim signHere2 As SignHere = New SignHere
With signHere2
.AnchorString = "/sn1/"
.AnchorUnits = "pixels"
.AnchorYOffset = "10"
.AnchorXOffset = "20"
End With
' Tabs are set per recipient / signer
Dim signer1Tabs As Tabs = New Tabs
Dim SignHereList As New List(Of SignHere)
SignHereList.Add(signHere1)
SignHereList.Add(signHere2)
signer1Tabs.SignHereTabs = SignHereList
signer1.Tabs = signer1Tabs
' Add the recipients to the envelope object
Dim Recipients As Recipients = New Recipients
Dim Signers As New List(Of Signer)
Signers.Add(signer1)
Dim CarbonCopies As New List(Of CarbonCopy)
CarbonCopies.Add(CC1)
Recipients.CarbonCopies = CarbonCopies
Recipients.Signers = Signers
env.Recipients = Recipients
' Request that the envelope be sent by setting |status| to "sent".
' To request that the envelope be created as a draft, set to "created"
env.Status = envStatus
Return env
End Function
'---------------------------------------
Private Function GetaccessToken() As String
Dim ac As ApiClient = New ApiClient()
Dim privateKeyStream() As Byte = System.IO.File.ReadAllBytes("c:\scratch\privatekey.txt") 'Location of file with Private Key.
Dim tokenInfo As OAuth.OAuthToken = ac.RequestJWTUserToken("Your Client ID",
"Your User ID",
"account-d.docusign.com",
privateKeyStream,
1)
Return tokenInfo.access_token
End Function
'---------------------------------------
End Class
刚刚开始在我的网站上实施 Docusign。 (.NET VB.NET)
需要确保我选择了正确的授权类型来访问 API。
用户将登录网站并将 select 文档发送给指定的收件人。
公司将拥有一个用于所有文档签名的整体 DocuSign 帐户。用户将没有单独的 DocuSign 帐户,但他们将有单独的网站登录凭据。
我认为这是 JWT 的情况,但不确定。有没有更简单的方法来授权每个签名?
感谢任何想法。
对我来说听起来像是智威汤逊。另请注意以下事项:
JSON Web 令牌 (JWT) 身份验证使开发人员能够代表某些用户请求令牌,而无需该用户登录。这意味着除了第一次,当用户必须同意时,无需网络 UI 即可获取令牌。 JWT 令牌用于特定帐户中的特定用户,它是用于唯一标识用户的用户 ID 的 GUID。如果您有多个帐户,则必须确保为正确的帐户使用正确的用户 ID。另请注意,DocuSign 中的用户具有不同的权限配置文件,并且可能具有也可能不具有执行 API 尝试执行的操作所需的访问权限。 JWT 可能不是允许许多不同用户使用他们自己的 DocuSign 登录名发送信封的 Web 应用程序的最佳选择。对于这些场景,授权码授予是更合适的模型,因为它要求最终用户在生成用于访问 API 的令牌之前使用其凭据登录 DocuSign。
我终于可以使用 vb.net 了。显然没有适合我们 vb 开发人员的文档,所以如果它可能对其他人有帮助,我 post 我的代码在这里。流程从过程“Button1_Click”开始......它将文档发送给收件人进行签名,并将 returns Docusign 结果响应发送到文本框“txtResult”。这基于转换为 vb.net 的 C# 文档中的演示过程。私钥是从本地 .txt 文件中读取的,该文件包含包含 -----BEGIN PRIVATE KEY---- 和 ----END PRIVATE KEY---- 标志的密钥。
Imports System.IO
Imports System.Net
Imports System.Text
Imports DocuSign.eSign.Api
Imports DocuSign.eSign.Client
Imports DocuSign.eSign.Client.Auth
Imports DocuSign.eSign.Model
Partial Class DocusignTest
Inherits System.Web.UI.Page
'---------------------------------------
'Process Begins With This Button Click....
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
txtResult.Text = SendEnvelopeViaEmail("recip1@wherever.com",
"Recip1 Name",
"recip2@anotherplace.com",
"Recip2 Name",
GetaccessToken(),
"https://demo.docusign.net/restapi",
"Your Account ID",
"C:\Users\Dotne\Downloads\World_Wide_Corp_Battle_Plan_Trafalgar.docx",
"C:\Users\Dotne\Downloads\World_Wide_Corp_lorem.pdf",
"sent")
End Sub
'---------------------------------------
Public Shared Function SendEnvelopeViaEmail(ByVal signerEmail As String,
ByVal signerName As String,
ByVal ccEmail As String,
ByVal ccName As String,
ByVal accessToken As String,
ByVal basePath As String,
ByVal accountId As String,
ByVal docDocx As String,
ByVal docPdf As String,
ByVal envStatus As String) As String
'/ <summary>
'/ Creates an envelope that would include two documents and add a signer and cc recipients to be notified via email
'/ </summary>
'/ <param name="signerEmail">Email address for the signer</param>
'/ <param name="signerName">Full name of the signer</param>
'/ <param name="ccEmail">Email address for the cc recipient</param>
'/ <param name="ccName">Name of the cc recipient</param>
'/ <param name="accessToken">Access Token for API call (OAuth)</param>
'/ <param name="basePath">BasePath for API calls (URI)</param>
'/ <param name="accountId">The DocuSign Account ID (GUID or short version) for which the APIs call would be made</param>
'/ <param name="docPdf">String of bytes representing the document (pdf)</param>
'/ <param name="docDocx">String of bytes representing the Word document (docx)</param>
'/ <param name="envStatus">Status to set the envelope to</param>
'/ <returns>EnvelopeId for the new envelope</returns>
Dim env As EnvelopeDefinition = MakeEnvelope(signerEmail, signerName, ccEmail, ccName, docDocx, docPdf, envStatus)
Dim apiClient As ApiClient = New ApiClient(basePath)
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " & accessToken)
Dim envelopesApi As EnvelopesApi = New EnvelopesApi(apiClient)
Dim results As EnvelopeSummary = envelopesApi.CreateEnvelope(accountId, env)
Return results.EnvelopeId
End Function
'---------------------------------------
Private Shared Function MakeEnvelope(ByVal signerEmail As String, ByVal signerName As String, ByVal ccEmail As String, ByVal ccName As String, ByVal docDocx As String, ByVal docPdf As String, ByVal envStatus As String) As EnvelopeDefinition
' Data for this method
' Config.docDocx
' Config.docPdf
' RequestItemsService.Status -- the envelope status ('created' or 'sent')
' document 1 (html) has tag **signature_1**
' document 2 (docx) has tag /sn1/
' document 3 (pdf) has tag /sn1/
'
' The envelope has two recipients.
' recipient 1 - signer
' recipient 2 - cc
' The envelope will be sent first to the signer.
' After it is signed, a copy is sent to the cc person.
' read files from a local directory
' The reads could raise an exception if the file is not available!
Dim document1 = Encoding.UTF8.GetBytes(" <!DOCTYPE html>\n" &
" <html>" &
" <head>" &
" <meta charset='UTF-8'>" &
" </head>" &
" <body style=""font-family:sans-serif;margin-left:2em;"">" &
" <h1 style=""font-family: 'Trebuchet MS', Helvetica, sans-serif;" &
" color: darkblue;margin-bottom: 0;"">World Wide Corp</h1>" &
" <h2 style=""font-family: 'Trebuchet MS', Helvetica, sans-serif;" &
" margin-top: 0px;margin-bottom: 3.5em;font-size: 1em;" &
" color: darkblue;"">Order Processing Division</h2>" &
" <h4>Ordered by " & signerName & "</h4>" &
" <p style=""margin-top: 0em; margin-bottom:0em;"">Email: " & signerEmail & "</p>" &
" <p style=""margin-top:0em; margin-bottom:0em;"">Copy to: " & ccName & ", " & ccEmail & "</p>" &
" <p style=""margin-top:3em;"">" &
" Candy bonbon pastry jujubes lollipop wafer biscuit biscuit. Topping brownie sesame snaps sweet roll pie. Croissant danish biscuit soufflé caramels jujubes jelly. Dragée danish caramels lemon drops dragée. Gummi bears cupcake biscuit tiramisu sugar plum pastry. Dragée gummies applicake pudding liquorice. Donut jujubes oat cake jelly-o. Dessert bear claw chocolate cake gummies lollipop sugar plum ice cream gummies cheesecake." &
" </p>" &
" <!-- Note the anchor tag for the signature field Is in white. -->" &
" <h3 style=""margin-top:3em;"">Agreed: <span style=""color:white;"">**signature_1**/</span></h3>" &
" </body>" &
" </html>")
Dim doc2DocxBytes As String = Convert.ToBase64String(System.IO.File.ReadAllBytes(docDocx))
Dim doc3PdfBytes As String = Convert.ToBase64String(System.IO.File.ReadAllBytes(docPdf))
' create the envelope definition
Dim env As EnvelopeDefinition = New EnvelopeDefinition()
env.EmailSubject = "Please sign this document set"
' Create document objects, one per document
Dim doc1 As Document = New Document()
Dim b64 As String = Convert.ToBase64String(document1) '(signerEmail, signerName, ccEmail, ccName)
With doc1
.DocumentBase64 = b64
.Name = "Order acknowledgement" ' can be different from actual file name
.FileExtension = "html" ' Source data format. Signed docs are always pdf.
.DocumentId = "1" ' a label used to reference the doc
End With
Dim doc2 As Document = New Document
With doc2
.DocumentBase64 = doc2DocxBytes
.Name = "Battle Plan"
.FileExtension = "docx"
.DocumentId = "2"
End With
Dim doc3 As Document = New Document
With doc3
.DocumentBase64 = doc3PdfBytes
.Name = "Lorem Ipsum"
.FileExtension = "pdf"
.DocumentId = "3"
End With
' The order in the docs array determines the order in the envelope
Dim DocList As New List(Of Document)
DocList.Add(doc1)
DocList.Add(doc2)
DocList.Add(doc3)
env.Documents = DocList
' create a signer recipient to sign the document, identified by name and email
Dim signer1 As Signer = New Signer
With signer1
.Email = signerEmail
.Name = signerName
.RecipientId = "1"
.RoutingOrder = "1"
End With
' routingOrder (lower means earlier) determines the order of deliveries
' to the recipients. Parallel routing order is supported by using the
' same integer as the order for two or more recipients.
' create a cc recipient to receive a copy of the documents, identified by name and email
Dim CC1 As CarbonCopy = New CarbonCopy
With CC1
.Email = ccEmail
.Name = ccName
.RecipientId = "2"
.RoutingOrder = "2"
End With
' Create signHere fields (also known as tabs) on the documents,
' We're using anchor (autoPlace) positioning
'
' The DocuSign platform searches throughout your envelope's
' documents for matching anchor strings. So the
' signHere2 tab will be used in both document 2 and 3 since they
' use the same anchor string for their "signer 1" tabs.
Dim signHere1 As SignHere = New SignHere
With signHere1
.AnchorString = "**signature_1**"
.AnchorUnits = "pixels"
.AnchorYOffset = "10"
.AnchorXOffset = "20"
End With
Dim signHere2 As SignHere = New SignHere
With signHere2
.AnchorString = "/sn1/"
.AnchorUnits = "pixels"
.AnchorYOffset = "10"
.AnchorXOffset = "20"
End With
' Tabs are set per recipient / signer
Dim signer1Tabs As Tabs = New Tabs
Dim SignHereList As New List(Of SignHere)
SignHereList.Add(signHere1)
SignHereList.Add(signHere2)
signer1Tabs.SignHereTabs = SignHereList
signer1.Tabs = signer1Tabs
' Add the recipients to the envelope object
Dim Recipients As Recipients = New Recipients
Dim Signers As New List(Of Signer)
Signers.Add(signer1)
Dim CarbonCopies As New List(Of CarbonCopy)
CarbonCopies.Add(CC1)
Recipients.CarbonCopies = CarbonCopies
Recipients.Signers = Signers
env.Recipients = Recipients
' Request that the envelope be sent by setting |status| to "sent".
' To request that the envelope be created as a draft, set to "created"
env.Status = envStatus
Return env
End Function
'---------------------------------------
Private Function GetaccessToken() As String
Dim ac As ApiClient = New ApiClient()
Dim privateKeyStream() As Byte = System.IO.File.ReadAllBytes("c:\scratch\privatekey.txt") 'Location of file with Private Key.
Dim tokenInfo As OAuth.OAuthToken = ac.RequestJWTUserToken("Your Client ID",
"Your User ID",
"account-d.docusign.com",
privateKeyStream,
1)
Return tokenInfo.access_token
End Function
'---------------------------------------
End Class