private string AuthenticateJWT() { const int EXPIRE_HOURS = 1; if (AuthConfig == null) { throw new DocuSignException("Auth config not initialized"); } string accountID = string.Empty; ds.Client.ApiClient apiClient = new ds.Client.ApiClient(AuthConfig.Host); apiClient.ConfigureJwtAuthorizationFlow( AuthConfig.IntegratorKey, AuthConfig.UserID, AuthConfig.OAuthBasePath, AuthConfig.PrivateKeyPath, EXPIRE_HOURS); ds.Api.AuthenticationApi authApi = new ds.Api.AuthenticationApi(apiClient.Configuration); ds.Model.LoginInformation loginInfo = authApi.Login(); // find the default account for this user var account = loginInfo.LoginAccounts?.Where(x => x.IsDefault == "true").FirstOrDefault(); if (account == null) { throw new DocuSignException("No accounts found or unable to determine default account"); } return(account.AccountId); }
/// <summary> /// Init DocuSign ApiClient /// </summary> /// <param name="senderUsername"></param> /// <param name="senderPassword"></param> /// <returns></returns> public static LoginInformation GetDocuSignApiClient(string senderUsername, string senderPassword, string senderIntegratorKey) { //bool loggedIn = loginInfo.LoginAccounts.Where(a => a.UserName == senderUsername && a.ApiPassword == senderPassword) if (loginInfo == null) { var apiClient = new DocuSign.eSign.Client.ApiClient(basePath); // set client in global config so we don't need to pass it to each API object DocuSign.eSign.Client.Configuration.Default.ApiClient = apiClient; string authHeader = "{\"Username\":\"" + senderUsername + "\", \"Password\":\"" + senderPassword + "\", \"IntegratorKey\":\"" + senderIntegratorKey + "\"}"; DocuSign.eSign.Client.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader); //2 the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object AuthenticationApi authApi = new AuthenticationApi(); loginInfo = authApi.Login(); } //else // loginInfo.LoginAccounts.Add(); return(loginInfo); }
public async Task <IActionResult> OnPostAsync([FromRoute] string accessCode, [FromRoute] Guid taxId) { var tax = await _taxBiz.Get(new BaseCoreModel { Id = taxId }); var result = await _membershipServiceApi.SystemUserApiService.Get( new MembershipService.ApiClient.Models.BaseModel { Id = tax.Data.User.Id }); var bytesAsync = await global::System.IO.File.ReadAllBytesAsync( "/home/ubuntu/Workdir/AccnetEngagement.pdf"); var documentBase64 = Convert.ToBase64String(bytesAsync); var accessToken = await _docusignHttpClient.GetAccessToken(accessCode); var userInfo = await _docusignHttpClient.GetUserInfo(accessToken.Data); Document document = new Document { DocumentBase64 = documentBase64, Name = "test", FileExtension = "pdf", DocumentId = "1" }; Document[] documents = new Document[] { document }; // Create the signer recipient object Signer signer = new Signer { Email = userInfo.Data.email, Name = userInfo.Data.name, ClientUserId = userInfo.Data.sub, RecipientId = "1", RoutingOrder = "1" }; // Create the sign here tab (signing field on the document) var dateSigned = new DocuSign.eSign.Model.DateSigned() { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Date Signed Tab", XPosition = "70", YPosition = "120", Value = DateTime.Now.ToString("d") }; var fullName1 = new DocuSign.eSign.Model.Text() { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Full Name Tab", XPosition = "69", YPosition = "130", Value = result.Data.Firstname + " " + result.Data.Lastname }; var text = new DocuSign.eSign.Model.Text() { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Text Tab", XPosition = "69", YPosition = "140", Value = result.Data.Address }; var fullName4 = new DocuSign.eSign.Model.Text { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Full Name Tab", XPosition = "100", YPosition = "155", Value = result.Data.Gender + " " + result.Data.Firstname + " " + result.Data.Lastname }; var text1 = new DocuSign.eSign.Model.Text() { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Text Tab", XPosition = "370", YPosition = "202", Value = tax.Data.Title }; var text2 = new DocuSign.eSign.Model.Text() { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Text Tab", XPosition = "150", YPosition = "260", Value = tax.Data.Title }; var fullName2 = new DocuSign.eSign.Model.Text { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Full Name Tab", XPosition = "240", YPosition = "260", Value = result.Data.Firstname + " " + result.Data.Lastname }; var fullName3 = new DocuSign.eSign.Model.Text { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Full Name Tab", XPosition = "430", YPosition = "260", Value = result.Data.Firstname + " " + result.Data.Lastname }; SignHere signHereTab = new SignHere { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Sign Here Tab", XPosition = "400", YPosition = "650" }; SignHere[] signHereTabs = new SignHere[] { signHereTab }; DateSigned[] dateSigns = new DateSigned[] { dateSigned }; Text[] texts = new Text[] { text, text1, text2, fullName1, fullName2, fullName3, fullName4 }; // Add the sign here tab array to the signer object. signer.Tabs = new Tabs { SignHereTabs = new List <SignHere>(signHereTabs), DateSignedTabs = new List <DateSigned>(dateSigns), TextTabs = new List <Text>(texts) }; // Create array of signer objects Signer[] signers = new Signer[] { signer }; // Create recipients object Recipients recipients = new Recipients { Signers = new List <Signer>(signers) }; // Bring the objects together in the EnvelopeDefinition EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition { EmailSubject = "Please sign the document", Documents = new List <Document>(documents), Recipients = recipients, Status = "sent" }; // 2. Use the SDK to create and send the envelope var apiClient = new DocuSign.eSign.Client.ApiClient(basePath); apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken.Data); EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration); EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelopeDefinition); // 3. Create Envelope Recipient View request obj string envelopeId = results.EnvelopeId; RecipientViewRequest viewOptions = new RecipientViewRequest { ReturnUrl = returnUrl, ClientUserId = userInfo.Data.sub, AuthenticationMethod = "none", UserName = userInfo.Data.name, Email = userInfo.Data.email }; // 4. Use the SDK to obtain a Recipient View URL ViewUrl viewUrl = envelopesApi.CreateRecipientView(accountId, envelopeId, viewOptions); return(Ok(Result <string> .Successful(viewUrl.Url))); }
public IActionResult Sign(BaseCoreModel coreModel) { // Embedded Signing Ceremony // 1. Create envelope request obj // 2. Use the SDK to create and send the envelope // 3. Create Envelope Recipient View request obj // 4. Use the SDK to obtain a Recipient View URL // 5. Redirect the user's browser to the URL // 1. Create envelope request object // Start with the different components of the request Document document = new Document { DocumentBase64 = Convert.ToBase64String(global::System.IO.File.ReadAllBytes("Path")), Name = "Lorem Ipsum", FileExtension = "pdf", DocumentId = "1" }; Document[] documents = new Document[] { document }; // Create the signer recipient object Signer signer = new Signer { Email = signerEmail, Name = signerName, ClientUserId = signerClientId, RecipientId = "1", RoutingOrder = "1" }; // Create the sign here tab (signing field on the document) SignHere signHereTab = new SignHere { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Sign Here Tab", XPosition = "195", YPosition = "147" }; SignHere[] signHereTabs = new SignHere[] { signHereTab }; // Add the sign here tab array to the signer object. signer.Tabs = new Tabs { SignHereTabs = new List <SignHere>(signHereTabs) }; // Create array of signer objects Signer[] signers = new Signer[] { signer }; // Create recipients object Recipients recipients = new Recipients { Signers = new List <Signer>(signers) }; // Bring the objects together in the EnvelopeDefinition EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition { EmailSubject = "Please sign the document", Documents = new List <Document>(documents), Recipients = recipients, Status = "sent" }; // 2. Use the SDK to create and send the envelope DocuSign.eSign.Client.ApiClient apiClient = new DocuSign.eSign.Client.ApiClient(basePath); apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration); EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelopeDefinition); // 3. Create Envelope Recipient View request obj string envelopeId = results.EnvelopeId; RecipientViewRequest viewOptions = new RecipientViewRequest { ReturnUrl = "localhost:5000", ClientUserId = signerClientId, AuthenticationMethod = "none", UserName = signerName, Email = signerEmail }; // 4. Use the SDK to obtain a Recipient View URL ViewUrl viewUrl = envelopesApi.CreateRecipientView(accountId, envelopeId, viewOptions); // 5. Redirect the user's browser to the URL return(Redirect(viewUrl.Url)); }
public DocuSign.eSign.Client.Configuration Configuration(DocuSign.eSign.Client.ApiClient apiClient = null) { return(new DocuSign.eSign.Client.Configuration(apiClient)); }