/// <summary> /// Builds Credentials from /// </summary> /// <param name="apiKey"></param> /// <param name="signatureSecret"></param> /// <param name="method"></param> /// <returns></returns> public static Credentials FromApiKeySignatureSecretAndMethod(string apiKey, string signatureSecret, SmsSignatureGenerator.Method method) { return(new Credentials() { ApiKey = apiKey, SecuritySecret = signatureSecret, Method = method }); }
/// <summary> /// Adds a piece of middleware to handle Inbound SMS messages. Will return a 204 if it encounters a valid sms, 401 if it can't authenticate the SMS, and a 500 if anything else goes wrong /// </summary> /// <param name="builder"></param> /// <param name="handler">Delegate to handle the inbound SMS</param> /// <param name="path">the route you'd like to handle the inbound SMS over, this should correspond to what you've set in the vonage dashboard</param> /// <param name="signatureSecret">The signature secret to validate the SMS Against, defaults to null, if this is not set the SMS will not be validated</param> /// <param name="method">Signature method to use for validating SMS messages</param> /// <param name="invokeNextMiddleware">Whetehr to invoke the next piece of middleware in your pipeline, if this is false this middleware will exit immediately after completing</param> /// <returns></returns> public static IApplicationBuilder UseVonageSms(this IApplicationBuilder builder, InboundSmsDelegate handler, string path = "/webhooks/inbound-sms", string signatureSecret = null, SmsSignatureGenerator.Method method = SmsSignatureGenerator.Method.md5hash, bool invokeNextMiddleware = false) { return(builder.Map(path, b => b.UseMiddleware <InboundSmsWebhookHandler>(handler, signatureSecret, method, invokeNextMiddleware))); }
internal InboundSmsWebhookHandler(RequestDelegate next, InboundSmsDelegate handler, string signatureSecret = null, SmsSignatureGenerator.Method method = SmsSignatureGenerator.Method.md5hash, bool invokeNext = false) { _delegate = handler; _next = next; _signatureSecret = signatureSecret; _signatureMethod = method; _invokeNextMiddleware = invokeNext; }
public bool ValidateSignature(string signatureSecret, SmsSignatureGenerator.Method method) { //use json representation to create a useable dictionary var json = JsonConvert.SerializeObject(this, Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(json); var signatureString = ConstructSignatureStringFromDictionary(dict); var testSig = SmsSignatureGenerator.GenerateSignature(signatureString, signatureSecret, method).ToString(); System.Diagnostics.Debug.WriteLine(testSig); Console.WriteLine(testSig); return(testSig == Sig); }
public ActionResult SendSignedSms(string to, string from, string message, string NEXMO_API_KEY, string NEXMO_API_SIGNATURE_SECRET, SmsSignatureGenerator.Method method) { var results = SMSSender.SendSignedSms(to, from, message, NEXMO_API_KEY, NEXMO_API_SIGNATURE_SECRET, method); if (results.messages.Count >= 1) { if (results.messages[0].status == "0") { ViewBag.unicoderesult = "Message sent successfully."; Debug.WriteLine("Message sent successfully."); } else { ViewBag.unicoderesult = $"Message failed with error: { results.messages[0].error_text}"; Debug.WriteLine($"Message failed with error: {results.messages[0].error_text}"); } } return(View("Index")); }
public static SMS.SMSResponse SendSignedSms(string TO_NUMBER, string NEXMO_BRAND_NAME, string message, string NEXMO_API_KEY, string NEXMO_API_SIGNATURE_SECRET, SmsSignatureGenerator.Method method) { var client = new Nexmo.Api.Client(new Nexmo.Api.Request.Credentials() { ApiKey = NEXMO_API_KEY, SecuritySecret = NEXMO_API_SIGNATURE_SECRET, Method = method }); var results = client.SMS.Send(new SMS.SMSRequest { from = NEXMO_BRAND_NAME, to = TO_NUMBER, text = message }); return(results); }