/// <summary> /// Initializes a new instance of the Configuration class. /// </summary> /// <param name="apiClient">Api client.</param> public Configuration(ApiClient apiClient=null) { if (apiClient == null) ApiClient = ApiClient.Default; else ApiClient = apiClient; }
internal static void ConfigureApiClient() { ApiClient apiClient = new ApiClient(TestConfig.BaseUrl); string authHeader = Utils.CreateAuthHeader(TestConfig.UserName, TestConfig.Password, TestConfig.IntegratorKey); // set client in global config so we don't need to pass it to each API object. Configuration.Default.ApiClient = apiClient; if (Configuration.Default.DefaultHeader.ContainsKey("X-DocuSign-Authentication")) { Configuration.Default.DefaultHeader.Remove("X-DocuSign-Authentication"); } Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader); }
public void OAuthAuthorizationCodeFlowTest() { // Initiate the browser session to the Authentication server // so the user can login. string accountServerAuthUrl = string.Format("https://{0}/oauth/auth?response_type=code&scope=all&client_id={1}&redirect_uri={2}&state=testState", AccountServerHost, client_id, redirect_url, stateOptional); System.Diagnostics.Process.Start(accountServerAuthUrl); WaitForCallbackEvent = new ManualResetEvent(false); // Launch a self-hosted web server to accepte the redirect_url call // after the user finishes authencation. using (WebApp.Start<Startup>("http://localhost:8090")) { Trace.WriteLine("WebServer Running- Waiting for access_token"); // This waits for the redirect_url to be received in the REST controller // (see classes below) and then sleeps a short time to allow the response // to be returned to the web browser before the server session ends. WaitForCallbackEvent.WaitOne(60000, false); Thread.Sleep(1000); } Assert.IsNotNull(AccessCode); // The Authentication is completed, so now echange a code returned for // the access_token and refresh_token var webClient = new WebClient(); webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); // Add the Authorization header with client_id and client_secret as base64 string codeAuth = client_id + ":" + client_secret; byte[] codeAuthBytes = Encoding.UTF8.GetBytes(codeAuth); string codeAuthBase64 = Convert.ToBase64String(codeAuthBytes); webClient.Headers.Add("Authorization", "Basic " + codeAuthBase64); // Add the code returned from the Authentication site string tokenGrantAndCode = string.Format("grant_type=authorization_code&code={0}", AccessCode); // Call the token endpoint to exchange the code for an access_token string tokenEndpoint = string.Format("https://{0}/oauth/token", AccountServerHost); string tokenResponse = webClient.UploadString(tokenEndpoint, tokenGrantAndCode); TokenResponse tokenObj = JsonConvert.DeserializeObject<TokenResponse>(tokenResponse); Assert.IsNotNull(tokenObj); Assert.IsNotNull(tokenObj.access_token); Trace.WriteLine("Access_token: " + tokenObj.access_token); // Make an API call with the token ApiClient apiClient = new ApiClient(BaseUrl); DocuSign.eSign.Client.Configuration.Default.ApiClient = apiClient; DocuSign.eSign.Client.Configuration.Default.AddDefaultHeader("Authorization", "Bearer " + tokenObj.access_token); AccountsApi accountsApi = new AccountsApi(); AccountInformation accountInformation = accountsApi.GetAccountInformation("1"); Trace.WriteLine(accountInformation.ToString()); // Generally the refresh token is stored away and used to get a new access_token without authenticating via the browser // when the access_token expires (see expires_in). Here we test that the refresh_token can be // exchanged for a new access_token webClient = new WebClient(); webClient.Headers.Add("Authorization", "Basic " + codeAuthBase64); webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); // Add the code returned from the Authentication site string refreshGrant = string.Format("grant_type=refresh_token&refresh_token={0}", tokenObj.refresh_token); tokenResponse = webClient.UploadString(tokenEndpoint, refreshGrant); tokenObj = JsonConvert.DeserializeObject<TokenResponse>(tokenResponse); Assert.IsNotNull(tokenObj); Assert.IsNotNull(tokenObj.access_token); Trace.WriteLine("Access_token (After Refresh): " + tokenObj.access_token); // Try another call with new acccess token accountInformation = accountsApi.GetAccountInformation("1"); Trace.WriteLine(accountInformation.ToString()); }
public static void Execute() { // Enter your DocuSign credentials var credentials = new DocusignQuickStart.DocusignCredentials { Username = "******", Password = "******", IntegratorKey = "81f3bae3-f472-4a51-8d5f-e966f74cb0ab" }; // specify the document (file) we want signed string SignTest1File = @"C:\Users\callu_000\Documents\UD Group\Docusign\CNG\CNG Contract.pdf"; // Enter recipient (signer) name and email address string recipientName = "Callum Rigby"; string recipientEmail = "*****@*****.**"; string recipientName2 = "John Smith"; string recipientEmail2 = "*****@*****.**"; // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi) string basePath = "https://demo.docusign.net/restapi"; // instantiate a new api client var apiClient = new ApiClient(basePath); // set client in global config so we don't need to pass it to each API object Configuration.Default.ApiClient = apiClient; string authHeader = JsonConvert.SerializeObject(credentials); //DocusignCredentials cred = JsonConvert.DeserializeObject<DocusignCredentials>(authHeader); Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader); // we will retrieve this from the login() results string accountId = null; // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object var authApi = new AuthenticationApi(); LoginInformation loginInfo = authApi.Login(); // user might be a member of multiple accounts accountId = loginInfo.LoginAccounts[0].AccountId; Console.WriteLine("LoginInformation: {0}", loginInfo.ToJson()); // Read a file from disk to use as a document byte[] fileBytes = File.ReadAllBytes(SignTest1File); var envDef = new EnvelopeDefinition(); envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc"; // Add a document to the envelope var doc = new Document(); doc.DocumentBase64 = Convert.ToBase64String(fileBytes); doc.Name = "TestFile.pdf"; doc.DocumentId = "1"; envDef.Documents = new List<Document>(); envDef.Documents.Add(doc); // Add a recipient to sign the documeent var signer = new Signer(); signer.Name = recipientName; signer.Email = recipientEmail; signer.RecipientId = "1"; signer.RoutingOrder = "1"; var signer2 = new Signer(); signer2.Name = recipientName2; signer2.Email = recipientEmail2; signer2.RecipientId = "2"; signer.RoutingOrder = "2"; // Create a |SignHere| tab somewhere on the document for the recipient to sign signer.Tabs = new Tabs(); signer.Tabs.SignHereTabs = new List<SignHere>(); var signHere = new SignHere(); signHere.DocumentId = "1"; signHere.PageNumber = "1"; signHere.RecipientId = "1"; signHere.XPosition = "100"; signHere.YPosition = "150"; signer.Tabs.SignHereTabs.Add(signHere); signer2.Tabs = new Tabs(); signer2.Tabs.SignHereTabs = new List<SignHere>(); var signHere2 = new SignHere(); signHere.DocumentId = "1"; signHere.PageNumber = "1"; signHere.RecipientId = "2"; signHere.XPosition = "100"; signHere.YPosition = "200"; signer2.Tabs.SignHereTabs.Add(signHere); envDef.Recipients = new Recipients(); envDef.Recipients.Signers = new List<Signer>(); envDef.Recipients.Signers.Add(signer); envDef.Recipients.Signers.Add(signer2); // set envelope status to "sent" to immediately send the signature request envDef.Status = "sent"; // Use the EnvelopesApi to send the signature request! var envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); // print the JSON response Console.WriteLine("EnvelopeSummary:\n{0}", JsonConvert.SerializeObject(envelopeSummary)); Console.Read(); }
static void Main(string[] args) { // Enter your DocuSign credentials string Username = "******"; string Password = "******"; string IntegratorKey = "[INTEGRATOR_KEY]"; // specify the document (file) we want signed string SignTest1File = @"[PATH/TO/DOCUMENT/TEST.PDF]"; // Enter recipient (signer) name and email address string recipientName = "[SIGNER_NAME]"; string recipientEmail = "[SIGNER_EMAIL]"; // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi) string basePath = "https://demo.docusign.net/restapi"; // instantiate a new api client ApiClient apiClient = new ApiClient(basePath); // set client in global config so we don't need to pass it to each API object Configuration.Default.ApiClient = apiClient; string authHeader = "{\"Username\":\"" + Username + "\", \"Password\":\"" + Password + "\", \"IntegratorKey\":\"" + IntegratorKey + "\"}"; Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader); // we will retrieve this from the login() results string accountId = null; // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object AuthenticationApi authApi = new AuthenticationApi(); LoginInformation loginInfo = authApi.Login(); // user might be a member of multiple accounts accountId = loginInfo.LoginAccounts[0].AccountId; Console.WriteLine("LoginInformation: {0}", loginInfo.ToJson()); // Read a file from disk to use as a document byte[] fileBytes = File.ReadAllBytes(SignTest1File); EnvelopeDefinition envDef = new EnvelopeDefinition(); envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc"; // Add a document to the envelope Document doc = new Document(); doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes); doc.Name = "TestFile.pdf"; doc.DocumentId = "1"; envDef.Documents = new List<Document>(); envDef.Documents.Add(doc); // Add a recipient to sign the documeent Signer signer = new Signer(); signer.Name = recipientName; signer.Email = recipientEmail; signer.RecipientId = "1"; // Create a |SignHere| tab somewhere on the document for the recipient to sign signer.Tabs = new Tabs(); signer.Tabs.SignHereTabs = new List<SignHere>(); SignHere signHere = new SignHere(); signHere.DocumentId = "1"; signHere.PageNumber = "1"; signHere.RecipientId = "1"; signHere.XPosition = "100"; signHere.YPosition = "150"; signer.Tabs.SignHereTabs.Add(signHere); envDef.Recipients = new Recipients(); envDef.Recipients.Signers = new List<Signer>(); envDef.Recipients.Signers.Add(signer); // set envelope status to "sent" to immediately send the signature request envDef.Status = "sent"; // Use the EnvelopesApi to send the signature request! EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); // print the JSON response Console.WriteLine("EnvelopeSummary:\n{0}", JsonConvert.SerializeObject(envelopeSummary)); Console.Read(); }
/// <summary> /// Initializes a new instance of the Configuration class. /// </summary> /// <param name="apiClient">Api client.</param> public Configuration(ApiClient apiClient) { setApiClientUsingDefault(apiClient); }
public JsonResult <ViewUrl> Test() { string username = ""; string password = ""; string integratorKey = ""; // initialize client for desired environment (for production change to www) DSC.ApiClient apiClient = new DSC.ApiClient("https://demo.docusign.net/restapi"); DSC.Configuration.Default.ApiClient = apiClient; // configure 'X-DocuSign-Authentication' header string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}"; DSC.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader); // we will retrieve this from the login API call string accountId = null; ///////////////////////////////////////////////////////////////// // STEP 1: LOGIN API ///////////////////////////////////////////////////////////////// // login call is available in the authentication api AuthenticationApi authApi = new AuthenticationApi(); LoginInformation loginInfo = authApi.Login(); // parse the first account ID that is returned (user might belong to multiple accounts) accountId = loginInfo.LoginAccounts[0].AccountId; // Update ApiClient with the new base url from login call string[] separatingStrings = { "/v2" }; apiClient = new DSC.ApiClient(loginInfo.LoginAccounts[0].BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]); ///////////////////////////////////////////////////////////////// // STEP 2: CREATE ENVELOPE API ///////////////////////////////////////////////////////////////// // create a new envelope which we will use to send the signature request EnvelopeDefinition envDef = new EnvelopeDefinition(); envDef.EmailSubject = "[DocuSign C# SDK] - Sample Signature Request"; // provide a valid template ID from a template in your account // envDef.TemplateId = "7decf5f8-b499-4b51-8c3c-7c3a2702eefa"; Document doc = new Document(); Signer signer = new Signer(); Byte[] bytes = File.ReadAllBytes(@""); String file = Convert.ToBase64String(bytes); doc.DocumentBase64 = file; doc.DocumentId = "1"; doc.Name = "Mutual_NDA.pdf"; envDef.Documents = new List <Document>(); envDef.Documents.Add(doc); signer.Email = username; signer.Name = "Marc"; signer.RecipientId = "1"; signer.ClientUserId = "123"; envDef.Recipients = new Recipients(); envDef.Recipients.Signers = new List <Signer>(); envDef.Recipients.Signers.Add(signer); // assign recipient to template role by setting name, email, and role name. Note that the // template role name must match the placeholder role name saved in your account template. TemplateRole tRole = new TemplateRole(); tRole.Email = ""; tRole.Name = "Marc"; tRole.RoleName = "Signer"; // add the roles list with the our single role to the envelope List <TemplateRole> rolesList = new List <TemplateRole>() { tRole }; envDef.TemplateRoles = rolesList; // set envelope status to "sent" to immediately send the signature request envDef.Status = "sent"; // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests) EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); ViewUrl url = GetViewUrl(envelopesApi, envDef, envelopeSummary); return(Json(url)); }