/** * This method is used to request (POST)the OAuth2 token for a specific user to access SignNow Application. */ public Oauth2Token RequestToken(User user) { Oauth2Token requestedToken = null; try { var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/oauth2/token", Method.POST) .AddHeader("Accept", "application/json") .AddHeader("Authorization", "Basic " + config.GetBase64EncodedClientCredentials()) .AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.RequestFormat = DataFormat.Json; request.AddParameter("username", user.Email) .AddParameter("password", user.Password) .AddParameter("grant_type", "password"); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); requestedToken = JsonConvert.DeserializeObject <Oauth2Token>(json); } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(requestedToken); }
public static Oauth2Token ParseTokenBody(string tokenBody) { var jobject = JToken.Parse(tokenBody) as JObject; var token = new Oauth2Token(); foreach (var jprop in jobject.Properties()) { switch (jprop.Name) { case "token_type": token.TokenType = (string)jprop.Value; break; case "expires_in" : token.ExpiryDate = DateTime.Now + new TimeSpan(0, 0,(int) jprop.Value); break; case "access_token": token.AccessToken = (string) jprop.Value; break; case "refresh_token": token.RefreshToken = (string)jprop.Value; break; case "scope": token.Scope = ((string) jprop.Value).Split(' '); break; } } return token; }
public static Oauth2Token ParseTokenBody(string tokenBody) { var jobject = JToken.Parse(tokenBody) as JObject; var token = new Oauth2Token(); foreach (var jprop in jobject.Properties()) { switch (jprop.Name) { case "token_type": token.TokenType = (string)jprop.Value; break; case "expires_in": token.ExpiryDate = DateTime.Now + new TimeSpan(0, 0, (int)jprop.Value); break; case "access_token": token.AccessToken = (string)jprop.Value; break; case "refresh_token": token.RefreshToken = (string)jprop.Value; break; case "scope": token.Scope = ((string)jprop.Value).Split(' '); break; } } return(token); }
/// <summary> /// Gets the access token with a previously received code. /// </summary> /// <param name="client">Client.</param> /// <param name="user">User.</param> /// <param name="accessCode">Access code.</param> public void GetAccessTokenWithCode(ThirdPartyClient client, Coflnet.CoflnetUser user, string accessCode) { var request = new RestRequest(client.service.TokenPath); var restClient = new RestClient(client.service.GetUrl()); request.AddHeader("grant_type", "authorization_code"); request.AddHeader("client_id", client.id); request.AddHeader("client_secret", client.secret); request.AddHeader("code", accessCode); var response = restClient.Execute(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw new CoflnetException("oauth_failed", $"Oauth handshake failed, {client.service.Slug} responded with: `{response.Content}`"); } var binary = MessagePack.MessagePackSerializer.ConvertFromJson(response.Content); var content = MessagePack.MessagePackSerializer.Deserialize <OAuthResponse>(binary); Oauth2Token token = new Oauth2Token(user, content.access_token, client.service, System.DateTime.Now.AddSeconds(content.expires_in), content.refresh_token); user.ThirdPartyTokens[client.service.Slug] = token; }
/* * This method is used to create or POST the document that contains SignNow Document Field Tags. */ public Document CreateDocumentFieldExtract(Oauth2Token token, Document documentPath) { Document document = null; try { string requestBody = JsonConvert.SerializeObject(documentPath.FilePath, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/document/fieldextract", Method.POST) .AddHeader("Authorization", "Bearer " + token.AccessToken) .AddHeader("Content-Type", "multipart/form-data"); request.AddFile("file", documentPath.FilePath); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); document = JsonConvert.DeserializeObject <Document>(json); } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(document); }
/* * This method is used to Delete an event subscription. */ public EventSubscription DeleteEventSubscription(Oauth2Token token, string id) { EventSubscription result = null; try { string requestBody = JsonConvert.SerializeObject(token, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/event_subscription" + "/" + id, Method.DELETE) .AddHeader("Accept", "application/json") .AddHeader("Authorization", "Bearer " + token.AccessToken); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); result = JsonConvert.DeserializeObject <EventSubscription>(json); } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(result); }
public void VerifyToken() { string randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; User user = new User(); user.Email = randomEmail; user.Password = "******"; user.FirstName = "firstName"; user.LastName = "LastName"; User resultUser = cudasign.userService.Create(user); Assert.IsNotNull("No user id from creating user", resultUser.Id); resultUser.Password = "******"; Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser); Assert.IsNotNull("Access Token", requestedToken.AccessToken); Oauth2Token verifiedToken = cudasign.authenticationService.Verify(requestedToken.AccessToken); Assert.IsNotNull("Verify Token", verifiedToken.AccessToken); Assert.AreEqual(requestedToken.AccessToken, verifiedToken.AccessToken, "Verified"); Assert.AreNotSame(requestedToken.AccessToken, verifiedToken.RefreshToken, "Refresh Token"); }
/* * This method is used to (POST) merge the new document from the given template id in the SignNow Application */ public byte[] MergeDocuments(Oauth2Token token, Hashtable myMergeMap) { byte[] arr = null; try { string requestBody = JsonConvert.SerializeObject(myMergeMap, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/document/merge", Method.POST) .AddHeader("Accept", "application/json") .AddHeader("Content-Type", "application/pdf") .AddHeader("Authorization", "Bearer " + token.AccessToken); request.AddParameter("text/json", requestBody, ParameterType.RequestBody); var httpResponse = client.Execute(request); arr = httpResponse.RawBytes; } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(arr); }
/* * This method is used to (POST) create a new document from the given template id in the SignNow Application */ public Template CreateNewDocumentFromTemplate(Oauth2Token token, Template template) { Template templ = null; try { string requestBody = JsonConvert.SerializeObject(template, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/template" + "/" + template.Id + "/copy", Method.POST) .AddHeader("Accept", "application/json") .AddHeader("Content-Type", "application/json") .AddHeader("Authorization", "Bearer " + token.AccessToken); request.RequestFormat = DataFormat.Json; request.AddBody(template); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); templ = JsonConvert.DeserializeObject <Template>(json); } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(templ); }
/* * This method is used to download (POST) the document as PDF for a given user from the SignNow Application */ public Document ShareDocument(Oauth2Token token, string id) { Document document = null; try { string requestBody = JsonConvert.SerializeObject(token, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/document" + "/" + id + "/download/link", Method.POST) .AddHeader("Accept", "application/json") .AddHeader("Authorization", "Bearer " + token.AccessToken); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); document = JsonConvert.DeserializeObject <Document>(json); } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(document); }
public void GetUser() { String randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; User user = new User(); user.Email = randomEmail; user.Password = "******"; user.FirstName = "firstName"; user.LastName = "LastName"; User resultUser = cudasign.userService.Create(user); Assert.IsNotNull("No user id from creating user", resultUser.Id); resultUser.Password = "******"; Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser); Assert.IsNotNull("Access Token", requestedToken.AccessToken); resultUser.OAuth2Token = requestedToken; User getUser = cudasign.userService.Get(resultUser.OAuth2Token.AccessToken); Assert.AreEqual(resultUser.Id, getUser.Id, "Found"); }
/* * This method is used to Deletes a previously uploaded document */ public string DeleteDocument(Oauth2Token token, string id) { string message = null; try { string requestBody = JsonConvert.SerializeObject(token, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/document" + "/" + id, Method.DELETE) .AddHeader("Accept", "application/json") .AddHeader("Authorization", "Bearer " + token.AccessToken); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); JObject obj = JObject.Parse(json); if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.OK)) { message = obj["status"].ToString(); } else if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.BadRequest)) { message = obj["error"].ToString(); } } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(message); }
/* * This method is used to update [PUT] the document for a given user from the SignNow Application */ public Document UpdateDocument(Oauth2Token token, Dictionary <string, List <Fields> > fieldsMap, string id) { Document document = null; try { string requestBody = JsonConvert.SerializeObject(fieldsMap, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/document" + "/" + id, Method.PUT) .AddHeader("Accept", "application/json") .AddHeader("Content-Type", "application/json") .AddHeader("Authorization", "Bearer " + token.AccessToken); request.AddParameter("text/json", requestBody, ParameterType.RequestBody); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); document = JsonConvert.DeserializeObject <Document>(json); } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(document); }
public void CreateSimpleFieldTag() { string randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; User user = new User(); user.Email = randomEmail; user.Password = "******"; user.FirstName = "firstName"; user.LastName = "LastName"; User resultUser = cudasign.userService.Create(user); Assert.IsNotNull("No user id from creating user", resultUser.Id); resultUser.Password = "******"; Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser); Assert.IsNotNull("Access Token", requestedToken.AccessToken); Document doc = new Document(); if (Directory.Exists(InputdirPath)) { string[] DocFilePath = Directory.GetFiles(@InputdirPath); doc.FilePath = DocFilePath[0]; } Document document = cudasign.documentService.Create(requestedToken, doc); Assert.IsNotNull("DocumentId", document.Id); }
public void DeleteEventSubscription() { string randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; User user = new User(); user.Email = randomEmail; user.Password = "******"; user.FirstName = "firstName"; user.LastName = "LastName"; User resultUser = cudasign.userService.Create(user); Assert.IsNotNull("No user id from creating user", resultUser.Id); resultUser.Password = "******"; Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser); Assert.IsNotNull("Access Token", requestedToken.AccessToken); EventSubscription evs = new EventSubscription(); evs.Event = "document.create"; evs.CallbackUrl = "https://www.myapp.com/path/to/callback.php"; EventSubscription res = cudasign.documentService.CreateEventSubscription(requestedToken, evs); Assert.IsNotNull("Subscription Id Created", res.Id); EventSubscription deleteEvent = cudasign.documentService.DeleteEventSubscription(requestedToken, res.Id); Assert.AreEqual("deleted", deleteEvent.Status); }
/// <summary> /// /// </summary> /// <param name="code">The authorization code we get from service when user provides valid credentials. It is sent to the service to get the access token.</param> /// <returns></returns> public ActionResult GetAccessToken(string code) { string callbackUrl = Url.Action("GetAccessToken", "Oauth2", null, Request.Url.Scheme, Request.Url.Host); ILogger Logger = new PepperiLogger(); PublicAuthentication PublicAuthentication = new PublicAuthentication(Logger, Settings.OauthBaseUri, Settings.PublicApplication_ConsumerKey, Settings.PublicApplication_ConsumerSecret); Oauth2Token Oauth2Token = PublicAuthentication.GetAccessTokenByAuthorizationCode(code, callbackUrl, "READ", new TokenRepository(this.Session)); return(RedirectToAction("Transactions", "Transaction")); }
private void RemovedCallback(string key, object value, CacheItemRemovedReason reason) { Oauth2Token oauth2Token = new Oauth2Token(); string[] scopes = new string[] { "snsapi_base", "snsapi_userinfo" }; foreach (string scope in scopes) { oauth2Token.RemoveCache(scope); } logs.Info("AgentConfig RemovedCallback to remove token"); }
public void MergeDocuments() { string randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; User user = new User(); user.Email = randomEmail; user.Password = "******"; user.FirstName = "firstName"; user.LastName = "LastName"; User resultUser = cudasign.userService.Create(user); Assert.IsNotNull("No user id from creating user", resultUser.Id); resultUser.Password = "******"; Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser); Assert.IsNotNull("Access Token", requestedToken.AccessToken); Document doc1 = new Document(); Document doc2 = new Document(); if (Directory.Exists(InputdirPath) && Directory.GetFiles(@InputdirPath).Length >= 2) { string[] DocFilePath = Directory.GetFiles(@InputdirPath); doc1.FilePath = DocFilePath[0]; doc2.FilePath = DocFilePath[1]; } Document document1 = cudasign.documentService.Create(requestedToken, doc1); Assert.IsNotNull("DocumentId", document1.Id); Document document2 = cudasign.documentService.Create(requestedToken, doc2); Assert.IsNotNull("DocumentId", document2.Id); List <string> docIds = new List <string>(); docIds.Add(document1.Id); docIds.Add(document2.Id); Hashtable myMergeMap = new Hashtable(); myMergeMap.Add("document_ids", docIds); byte[] res = cudasign.documentService.MergeDocuments(requestedToken, myMergeMap); if (Directory.Exists(OutputdirPath)) { string dest = OutputdirPath + @"\Merge" + (document1.Id.Substring(1, 4) + document2.Id.Substring(1, 4)) + ".pdf"; File.WriteAllBytes(dest, res); } Assert.IsNotNull("Document Content", res.Length.ToString()); }
//ILog logs = LogManager.GetLogger("redirect_uri"); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string code = context.Request["code"]; string state = context.Request["state"]; string callback_url = context.Request["callback_url"]; if (!string.IsNullOrWhiteSpace(code) && !string.IsNullOrWhiteSpace(state) && callback_url.IndexOf("http://") != -1) { int id = int.Parse(state.Split(char.Parse("|"))[1]); callback_url = context.Server.UrlDecode(callback_url); Oauth2Token access_token = new Oauth2Token(); Oauth2 oauth2 = access_token.Get(code, state); string paras; string nonce_str, timestamp, sign; AgentSign.SetSign(id, out nonce_str, out timestamp, out sign); if (oauth2.scope == "snsapi_base") { paras = "openid=" + oauth2.openid + "&scope=" + oauth2.scope; paras += "&nonce_str=" + nonce_str + "×tamp=" + timestamp + "&sign=" + sign; callback_url = SetCallbackUrl(callback_url, paras); } else if (oauth2.scope == "snsapi_userinfo") { UserInfoApi userInfoEntity = new UserInfo().Get(oauth2.access_token, oauth2.openid); paras = "&scope=" + oauth2.scope + "&openid=" + userInfoEntity.openid + "&nickname=" + userInfoEntity.nickname + "&sex=" + userInfoEntity.sex; paras += "&city=" + userInfoEntity.city + "&province=" + userInfoEntity.province + "&country=" + userInfoEntity.country; paras += "&headimgurl=" + userInfoEntity.headimgurl + "&unionid=" + userInfoEntity.unionid; paras += "&nonce_str=" + nonce_str + "×tamp=" + timestamp + "&sign=" + sign; //logs.Fatal("paras:" + paras); callback_url = SetCallbackUrl(callback_url, paras); } //logs.Fatal("callback_url:" + callback_url); context.Response.Redirect(callback_url); } }
internal static ApiClient GetAapiClient_ForPublicApplication(HttpSessionStateBase Session, ILogger Logger) { string ApiBaseUri = Settings.ApiBaseUri; string OauthBaseUri = Settings.OauthBaseUri; string PublicApplication_ConsumerKey = Settings.PublicApplication_ConsumerKey; string PublicApplication_ConsumerSecret = Settings.PublicApplication_ConsumerSecret; TokenRepository Oauth2TokenRepository = new TokenRepository(Session); Oauth2Token Oauth2Token = Oauth2TokenRepository.GetOauth2Token(); var IAuthentication = new PublicAuthentication(Logger, OauthBaseUri, PublicApplication_ConsumerKey, PublicApplication_ConsumerSecret, Oauth2Token, Oauth2TokenRepository); ApiClient ApiClient = new ApiClient(ApiBaseUri, IAuthentication, Logger); return(ApiClient); }
public void CancelInvite() { string randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; User user = new User(); user.Email = randomEmail; user.Password = "******"; user.FirstName = "firstName"; user.LastName = "LastName"; User resultUser = cudasign.userService.Create(user); Assert.IsNotNull("No user id from creating user", resultUser.Id); resultUser.Password = "******"; Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser); Assert.IsNotNull("Access Token", requestedToken.AccessToken); Document doc = new Document(); if (Directory.Exists(InputdirPath)) { string[] DocFilePath = Directory.GetFiles(@InputdirPath); doc.FilePath = DocFilePath[0]; } Document document = cudasign.documentService.Create(requestedToken, doc); Assert.IsNotNull("DocumentId", document.Id); string toEmail = "deepak" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; Invitation invitation = new Invitation(); invitation.From = resultUser.Email; invitation.To = toEmail; string resinvite = cudasign.documentService.Invite(requestedToken, invitation, document.Id); Assert.AreEqual("success", resinvite); string cancelinvite = cudasign.documentService.CancelInvite(requestedToken, document.Id); Assert.AreEqual("success", cancelinvite); }
/* * This method is used to Download a collapsed document(Response Content = application/pdf) */ public byte[] DownloadCollapsedDocument(Oauth2Token token, string id) { byte[] arr = null; try { string requestBody = JsonConvert.SerializeObject(token, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/document" + "/" + id + "/download?type=collapsed", Method.GET) .AddHeader("Authorization", "Bearer " + token.AccessToken); var httpResponse = client.Execute(request); arr = httpResponse.RawBytes; } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(arr); }
public void DownloadCollapsedDocument() { string randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; User user = new User(); user.Email = randomEmail; user.Password = "******"; user.FirstName = "firstName"; user.LastName = "LastName"; User resultUser = cudasign.userService.Create(user); Assert.IsNotNull("No user id from creating user", resultUser.Id); resultUser.Password = "******"; Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser); Assert.IsNotNull("Access Token", requestedToken.AccessToken); Document doc = new Document(); if (Directory.Exists(InputdirPath)) { string[] DocFilePath = Directory.GetFiles(@InputdirPath); doc.FilePath = DocFilePath[0]; } Document document = cudasign.documentService.Create(requestedToken, doc); Assert.IsNotNull("DocumentId", document.Id); byte[] docarr = cudasign.documentService.DownloadCollapsedDocument(requestedToken, document.Id); if (Directory.Exists(OutputdirPath)) { string dest = OutputdirPath + @"\" + document.Id + ".pdf"; File.WriteAllBytes(dest, docarr); } Assert.IsNotNull("Document Content", docarr.Length.ToString()); }
/* * This method is used to (POST) invite the signers to sign on the document in the SignNow Application */ public string Invite(Oauth2Token token, Invitation invitation, string id) { string result = null; try { string requestBody = JsonConvert.SerializeObject(invitation, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/document" + "/" + id + "/invite?email=disable", Method.POST) .AddHeader("Accept", "application/json") .AddHeader("Content-Type", "application/json") .AddHeader("Authorization", "Bearer " + token.AccessToken); request.RequestFormat = DataFormat.Json; request.AddBody(invitation); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); JObject res = JObject.Parse(json); if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.OK)) { result = res["result"].ToString(); } else if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.BadRequest)) { result = res["error"].ToString(); } } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(result); }
/* * This method retrieves all the uploaded documents for the specified user. */ public Document[] GetDocuments(Oauth2Token token) { Document[] docs = new Document[100]; try { string requestBody = JsonConvert.SerializeObject(token, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/user/documentsv2", Method.GET) .AddHeader("Accept", "application/json") .AddHeader("Authorization", "Bearer " + token.AccessToken); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.OK)) { JArray jar = JArray.Parse(json); int i = 0; foreach (JObject jobj in jar) { docs[i] = JsonConvert.DeserializeObject <Document>(jobj.ToString()); i++; } } else if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.BadRequest)) { docs[0] = JsonConvert.DeserializeObject <Document>(json); } } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(docs); }
/** * This method is used to verify (GET) the OAuth2 token for a specific user to access SignNow Application. */ public Oauth2Token Verify(string AccessToken) { Oauth2Token verifyToken = null; try { var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/oauth2/token", Method.GET) .AddHeader("Authorization", "Bearer " + AccessToken) .AddHeader("Accept", "application/json"); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); verifyToken = JsonConvert.DeserializeObject <Oauth2Token>(json); } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(verifyToken); }
/* * This method is used to (POST)perform rolebased to invite the signers to sign on the document in the SignNow Application */ public string RoleBasedInvite(Oauth2Token token, EmailSignature emailSignature, string id) { string result = null; try { string requestBody = JsonConvert.SerializeObject(emailSignature, Formatting.Indented); var client = new RestClient(); client.BaseUrl = config.GetApiBase(); var request = new RestRequest("/document" + "/" + id + "/invite", Method.POST) .AddHeader("Accept", "application/json") .AddHeader("Content-Type", "application/json") .AddHeader("Authorization", "Bearer " + token.AccessToken); request.AddParameter("text/json", requestBody, ParameterType.RequestBody); var httpResponse = client.Execute(request); string json = httpResponse.Content.ToString(); JObject job = JObject.Parse(json); if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.OK)) { result = job["status"].ToString(); } else if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.BadRequest)) { result = job["error"].ToString(); } } catch (Exception ex) { Console.WriteLine(string.Format("Exception: {0}", ex.Message)); throw; } return(result); }
public void UpdateDocument() { string randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; User user = new User(); user.Email = randomEmail; user.Password = "******"; user.FirstName = "firstName"; user.LastName = "LastName"; User resultUser = cudasign.userService.Create(user); Assert.IsNotNull("No user id from creating user", resultUser.Id); resultUser.Password = "******"; Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser); Assert.IsNotNull("Access Token", requestedToken.AccessToken); Document doc = new Document(); if (Directory.Exists(InputdirPath)) { string[] DocFilePath = Directory.GetFiles(@InputdirPath); doc.FilePath = DocFilePath[0]; } Document document = cudasign.documentService.Create(requestedToken, doc); Assert.IsNotNull("DocumentId", document.Id); // Build the data for Texts Test Text text = new Text(); text.Size = 30; text.X = 61; text.Y = 72; text.PageNumber = 0; text.Font = "Arial"; text.Data = "A SAMPLE TEXT FIELD"; text.LineHeight = 9.075; Text text1 = new Text(); text1.Size = 30; text1.X = 61; text1.Y = 72; text1.PageNumber = 1; text1.Font = "Arial"; text1.Data = "A SAMPLE TEXT FIELD 2"; text1.LineHeight = 9.075; List <Fields> textsList = new List <Fields>(); textsList.Add(text); textsList.Add(text1); // Build the data for Checks Checkbox checks = new Checkbox(); checks.Width = 20; checks.Height = 20; checks.X = 234; checks.Y = 500; checks.PageNumber = 0; Checkbox checks1 = new Checkbox(); checks1.Width = 20; checks1.Height = 20; checks1.X = 200; checks1.Y = 53; checks.PageNumber = 1; List <Fields> checksList = new List <Fields>(); checksList.Add(checks); checksList.Add(checks1); // Creating the Fields Radio radiobutton = new Radio(); radiobutton.PageNumber = 1; radiobutton.X = 150; radiobutton.Y = 65; radiobutton.Width = 40; radiobutton.Height = 40; radiobutton.Check = 0; radiobutton.Value = "apple"; radiobutton.Created = "123456789"; Radio radiobutton1 = new Radio(); radiobutton1.PageNumber = 1; radiobutton1.X = 250; radiobutton1.Y = 55; radiobutton1.Width = 40; radiobutton1.Height = 40; radiobutton1.Check = 0; radiobutton1.Value = "cherry"; radiobutton1.Created = "123456789"; List <Fields> radioList = new List <Fields>(); radioList.Add(radiobutton); radioList.Add(radiobutton1); Fields fields = new Fields(); fields.X = 13; fields.Y = 133; fields.Width = 25; fields.Height = 121; fields.PageNumber = 1; fields.Role = "buyer"; fields.Required = true; fields.Type = "radiobutton"; fields.Radio = radioList; List <Fields> fieldsList = new List <Fields>(); fieldsList.Add(fields); Dictionary <string, List <Fields> > fieldsMap = new Dictionary <string, List <Fields> >(); fieldsMap.Add("texts", textsList); fieldsMap.Add("checks", checksList); fieldsMap.Add("fields", fieldsList); Document resultDoc = cudasign.documentService.UpdateDocument(requestedToken, fieldsMap, document.Id); Assert.IsNotNull("DocumentId", document.Id); }
public void RoleBasedInvite() { string randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; User user = new User(); user.Email = randomEmail; user.Password = "******"; user.FirstName = "firstName"; user.LastName = "LastName"; User resultUser = cudasign.userService.Create(user); Assert.IsNotNull("No user id from creating user", resultUser.Id); resultUser.Password = "******"; Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser); Assert.IsNotNull("Access Token", requestedToken.AccessToken); Document doc = new Document(); if (Directory.Exists(InputdirPath)) { string[] DocFilePath = Directory.GetFiles(@InputdirPath); doc.FilePath = DocFilePath[0]; } Document document = cudasign.documentService.Create(requestedToken, doc); Assert.IsNotNull("DocumentId", document.Id); // Build the data for Texts Test Text text = new Text(); text.Size = 30; text.X = 61; text.Y = 72; text.PageNumber = 0; text.Font = "Arial"; text.Data = "A SAMPLE TEXT FIELD"; text.LineHeight = 9.075; Text text1 = new Text(); text1.Size = 30; text1.X = 61; text1.Y = 72; text1.PageNumber = 1; text1.Font = "Arial"; text1.Data = "A SAMPLE TEXT FIELD 2"; text1.LineHeight = 9.075; List <Fields> textsList = new List <Fields>(); textsList.Add(text); textsList.Add(text1); // Build the data for Checks Checkbox checks = new Checkbox(); checks.Width = 20; checks.Height = 20; checks.X = 234; checks.Y = 500; checks.PageNumber = 0; Checkbox checks1 = new Checkbox(); checks1.Width = 20; checks1.Height = 20; checks1.X = 200; checks1.Y = 53; checks.PageNumber = 1; List <Fields> checksList = new List <Fields>(); checksList.Add(checks); checksList.Add(checks1); // Creating the Fields Radio radiobutton = new Radio(); radiobutton.PageNumber = 1; radiobutton.X = 150; radiobutton.Y = 65; radiobutton.Width = 40; radiobutton.Height = 40; radiobutton.Check = 0; radiobutton.Value = "apple"; radiobutton.Created = "123456789"; Radio radiobutton1 = new Radio(); radiobutton1.PageNumber = 1; radiobutton1.X = 250; radiobutton1.Y = 55; radiobutton1.Width = 40; radiobutton1.Height = 40; radiobutton1.Check = 0; radiobutton1.Value = "cherry"; radiobutton1.Created = "123456789"; List <Fields> radioList = new List <Fields>(); radioList.Add(radiobutton); radioList.Add(radiobutton1); Fields fields = new Fields(); fields.X = 13; fields.Y = 133; fields.Width = 25; fields.Height = 121; fields.PageNumber = 1; fields.Role = "signer"; fields.Required = true; fields.Type = "radiobutton"; fields.Radio = radioList; Fields fields1 = new Fields(); fields1.X = 20; fields1.Y = 133; fields1.Width = 122; fields1.Height = 60; fields1.PageNumber = 0; fields1.Role = "buyer"; fields1.Required = true; fields1.Type = "initials"; Fields fields2 = new Fields(); fields2.X = 35; fields2.Y = 133; fields2.Width = 122; fields2.Height = 60; fields2.PageNumber = 1; fields2.Role = "TestingRole"; fields2.Required = true; fields2.Type = "text"; List <Fields> fieldsList = new List <Fields>(); fieldsList.Add(fields); fieldsList.Add(fields1); fieldsList.Add(fields2); Dictionary <string, List <Fields> > fieldsMap = new Dictionary <string, List <Fields> >(); fieldsMap.Add("texts", textsList); fieldsMap.Add("checks", checksList); fieldsMap.Add("fields", fieldsList); Document resultDoc = cudasign.documentService.UpdateDocument(requestedToken, fieldsMap, document.Id); Document getDoc = cudasign.documentService.GetDocumentbyId(requestedToken, resultDoc.Id); Fields[] flds = getDoc.Fields; List <System.Collections.Hashtable> roleMapList = new List <System.Collections.Hashtable>(); EmailSignature emailSignature = new EmailSignature(); int counter = 0; //iterate over fields for (int i = 0; i < flds.Length; i++) { string toEmail = "deepak" + DateTime.Now.ToBinary().ToString() + "@mailinator.com"; System.Collections.Hashtable roleMap = new System.Collections.Hashtable(); roleMap.Add("email", toEmail); roleMap.Add("role_id", flds[i].RoleId); roleMap.Add("role", flds[i].Role); roleMap.Add("order", ++counter); roleMapList.Add(roleMap); } emailSignature.To = roleMapList; emailSignature.From = resultUser.Email; string[] ccuser = new string[] { "*****@*****.**", "*****@*****.**" }; emailSignature.CC = ccuser; emailSignature.Message = resultUser.Email + " asked you to sign this document"; emailSignature.Subject = "SignNow Invitation"; string resinvite = cudasign.documentService.RoleBasedInvite(requestedToken, emailSignature, document.Id); Assert.AreEqual("success", resinvite); }
public void SaveToken(Oauth2Token Oauth2Token) { this.Session["Oauth2Token"] = Oauth2Token; }