public static void APIPartnerSample(PartnerSDK.ServiceClient client) { Console.WriteLine("Get token for invitee"); var inviteeToken = client.OAuth2.GetAccessTokenForInvitee(SampleParameters.Invitee1_FirstName, SampleParameters.Invitee1_LastName, SampleParameters.Invitee1_Email, SecuredSigningClientSdk.OAuth2Client.OAuth2Scope.Basic | SecuredSigningClientSdk.OAuth2Client.OAuth2Scope.SmartTag); client.AccessToken = inviteeToken.Access_Token; Console.WriteLine("Upload smart tag document"); var docRef = client.uploadDocumentFile(new System.IO.FileInfo(SampleParameters.Path2SmartTagDocument)); Console.WriteLine("Send smart tag"); var stResp = client.sendSmartTagDocument(new List<string> { docRef }, DateTime.Now.AddDays(3), true); Console.WriteLine("Populate signing key to embedded html page"); var signingKey = stResp.FirstOrDefault()?.Signers?.FirstOrDefault()?.SigningKey; Console.WriteLine(signingKey); var server = new Server.SampleServer() { SDKClient = client }; System.Diagnostics.Process.Start($"{SampleParameters.EmbeddedSigningUrl}?key={signingKey}"); var runResult = server.StartOnce(); Console.WriteLine("Go to browser to sign the document"); bool signed = false; while (!signed) { System.Threading.Thread.Sleep(5000); Console.WriteLine("Check document status"); var status = client.getStatus(docRef); if (status.Status == "Complete") { signed = true; } } Console.WriteLine("Done"); Console.Read(); }
static void Main(string[] args) { //initialise API Client var client = new ServiceClient( serviceUrl: SampleParameters.SecuredSigningServiceBase, version: SampleParameters.SecuredSigningServiceVersion, apiKey: SampleParameters.APIKey, secret: SampleParameters.APISecret, accessUrl: SampleParameters.CallbackUrl ); //see https://www.securedsigning.com/developer/api-documentation#auth for more details about OAuth 2, default enabled for API Key from March 2016. earlier API Key should ignore it. #region OAuth2 var state = SampleParameters.OAuth2State; //get OAuth2 access token in WinForm //Application.EnableVisualStyles(); //var form = new OAuth2AuthoriseForm(client, state, OAuth2Client.OAuth2Scope.Basic | OAuth2Client.OAuth2Scope.FormDirect | OAuth2Client.OAuth2Scope.FormFiller | OAuth2Client.OAuth2Scope.SmartTag); //form.OnAuthorized = (_tokenResp, _state) => //{ // System.Diagnostics.Debug.Assert(_state == state); // client.AccessToken = _tokenResp.Access_Token; // form.Close(); //}; //Application.Run(form); //AccountSample(client); //get OAuth2 access token in Server var authorizeUrl = client.OAuth2.CreateAuthorizeRequest(state, OAuth2Client.OAuth2Scope.Basic.ToString(), OAuth2Client.OAuth2Scope.FormDirect.ToString(), OAuth2Client.OAuth2Scope.FormFiller.ToString(), OAuth2Client.OAuth2Scope.SmartTag.ToString()); //start oauthorize process in a webpage System.Diagnostics.Process.Start(authorizeUrl); //run an server implemented by HttpListener, you can implement your own server using ASP.Net, etc. Server.SampleServer server = new Server.SampleServer(); var code = server.StartOnce(); var tokenResp = client.OAuth2.GetToken(code); client.AccessToken = tokenResp.Access_Token; tokenResp = client.OAuth2.RefreshToken(tokenResp.Refresh_Token); client.AccessToken = tokenResp.Access_Token; AccountSample(client); #endregion //FormDirectSample(client); //FormFillerSample(client); FormFillerSample_EmbeddedSigning(client); //SmartTagSample(client); Console.Read(); }
public static void FormFillerSample_EmbeddedSigning(ServiceClient client) { //get FormFiller templates var templates = client.getFormFillerTemplates(); //e.g. There're 3 templates. We select the second one. var t2 = templates[1]; //set Signer(s) for template //e.g. There's 1 signer in t2 //[ // { // "SignerReference": "048109...086112", // "FirstName": "", // "LastName": "", // "Email": "" // } //] t2.Signers = client.getFormFillerSignerTemplate(t2.Reference).Signers; t2.Signers[0].FirstName = SampleParameters.Invitee1_FirstName; t2.Signers[0].LastName = SampleParameters.Invitee1_LastName; t2.Signers[0].Email = SampleParameters.Invitee1_Email; //set Field(s) value for template (optional) //e.g. There's 2 fields in t2 //[ // { // "Label": "Question1", // "Value": "", // "FieldType": "Text", // "IsRequired": false, // "ID": "154107214180236225199245158115055014119106193119", // "ReadOnly": true // }, // { // "Label": "Question2", // "Value": "", // "FieldType": "Text", // "IsRequired": false, // "ID": "150138217070090110130118010201151101188219145216", // "ReadOnly": false // } //] var fields = client.getFormFillerFieldTemplate(t2.Reference).Fields; //e.g. We only want to prefill the first field t2.Fields = new List<SecuredSigningClientSdk.Models.FormFillerField>(); var f1 = fields[0]; f1.Value = SampleParameters.FormFillerSampleFieldValue; t2.Fields.Add(f1); //send template(s) var documents = client.sendFormFillerTemplates( templates: new List<SecuredSigningClientSdk.Models.FormFillerTemplate> { t2 }, dueDate: DateTime.Now.AddDays(5), embedded: true); var signingKey = documents.Signers.FirstOrDefault(t => !string.IsNullOrWhiteSpace(t.SigningKey))?.SigningKey; //populate signing key into a embedded signing webpage. //a sample server hosts the embedded signing webpage, implement your own page instead. Console.WriteLine(signingKey); var server = new Server.SampleServer() { SDKClient = client, KeepSecretInServer = true }; System.Diagnostics.Process.Start($"{SampleParameters.EmbeddedSigningUrl}?key={signingKey}"); var runResult = server.StartOnce(); Console.WriteLine("Go to browser to sign the document"); server.Listen(); bool signed = false; while (!signed) { System.Threading.Thread.Sleep(5000); Console.WriteLine("Check document status"); var status = client.getStatus(documents.Documents.First()?.Reference); if (status.Status == "Complete") { signed = true; } } server.Stop(); Console.WriteLine("Done"); Console.Read(); }