/// <summary> /// Asynchronously verify the phone code that the user inputted via Twilio. /// </summary> /// <param name="phoneNumber">The phone number the verification code was sent to (string)</param> /// <param name="phoneCode">User-inputtted phone code, attempt to match what was sent (string)</param> /// <returns>String indicating whether the verification was approved, is still pending, or failed</returns> public async Task <string> VerifyPhoneCodeAsync(string phoneNumber, string phoneCode) { // Must catch twilio.exceptions.twilioapiexception if they try to verify after expiration time or if the phone number // was not used in a verification. try { // Initiate the API with the credentials defined in the constants file. string accountSID = Constants.TwilioAccountSID; string authorizationToken = Constants.TwilioAuthToken; TwilioClient.Init(accountSID, authorizationToken); // Asynchronously attempt to verify the inputted code that was sent to the phone number, using the path service SID. var verificationCheck = await VerificationCheckResource.CreateAsync( to : $"+1{phoneNumber}", code : $"{phoneCode}", pathServiceSid : Constants.TwilioPathServiceSID ).ConfigureAwait(false); // Return the verification status. return(verificationCheck.Status); } catch (TwilioException) { return(Constants.TwilioAuthenticationFailString); } }
public async Task <IActionResult> CheckSms(string sid, string code, string userId, string isPersistent) { var verificationCheck = VerificationCheckResource.Create( verificationSid: sid, code: code, pathServiceSid: TwilioService.PathServiceSid ); if (verificationCheck.Valid == true) { var user = await _userManager.FindByIdAsync(userId); bool isPer = false; if (isPersistent == "True") { isPer = true; } await _signInManager.SignInAsync(user, isPer); return(Json(true)); } else { return(Json(false)); } }
public static string CheckRequest(VerifyModel verifyModel) { //var result = client.NumberVerify.Check(new NumberVerify.CheckRequest //{ // request_id = verifyModel.RequestId, // code = verifyModel.Code //}); //return result.error_text; //========================= const string accountSid = "ACcc94bdb5e63f5d18a39cb479b39ccbde"; const string authToken = "20c2e1517fddd3dc6f83cbae74dfe9c9"; TwilioClient.Init(accountSid, authToken); var verificationCheck = VerificationCheckResource.Create( to: "+84774543399", code: verifyModel.Code, pathServiceSid: "VAf73a8e1e711d3d54b9e738823e3543ff" ); return("xyz"); }
public static async Task <string> VerifyPhoneAsync(string phoneNumber, string countryCode, string num) { if (Env.Production) { string accountSid = TwilioConfig.AccountSid; string authToken = TwilioConfig.AuthToken; string pathServiceID = TwilioConfig.ServiceSid; TwilioClient.Init(accountSid, authToken); var verificationCheck = VerificationCheckResource.Create( to: "+" + countryCode + phoneNumber, code: num, pathServiceSid: pathServiceID ); if (verificationCheck.Valid == true) { return(verificationCheck.Status); } else { throw new Exception(verificationCheck.Status); } } else { return("success"); } }
public async Task <IActionResult> ConfirmPhone(string ConfirmCode) { try { var verification = await VerificationCheckResource.CreateAsync( to : "+84396987327", code : "439294", pathServiceSid : "XXX" ); if (verification.Status == "approved") { return(RedirectToAction("Index", "Home")); } else { return(View(ConfirmCode)); } } catch (System.Exception ex) { ViewBag.ErrorMessage = ex.Message; return(View(ConfirmCode)); } }
public async Task VerifyConfirmationSmsCodeAsync(string number, string code) { var verification = await VerificationCheckResource.CreateAsync( to : number, code : code, pathServiceSid : smsSettings.Service ); }
public async Task <VerificationCheckResource> VerifyCode(string phoneNumber, string code) { return(await VerificationCheckResource.CreateAsync( to : phoneNumber, code : code, pathServiceSid : _settings.VerificationServiceSID )); }
public string Get(string vercode) { var verificationCheck = VerificationCheckResource.Create( to: "+919003355434", code: vercode, pathServiceSid: "VA0e9bff2c70d29ee16ded98a8db8f1baf" ); return(verificationCheck.Status); }
public IActionResult CheckVerification([FromBody] CheckRequest request) { var verificationCheck = VerificationCheckResource.Create( to: $"+{request.CountryCode}{request.PhoneNumber}", code: request.Code, pathServiceSid: _options.VerifyServiceSid ); return(Ok(verificationCheck)); }
public static void CheckVerification() { TwilioClient.Init(SID, AuthToken); var verificationCheck = VerificationCheckResource.Create( to: "+2347037513959", code: "336406", pathServiceSid: "VA38170ed98248deabbaf93432c377f433" ); Console.WriteLine(verificationCheck.Status); }
public async Task <VerificationResult> ConfirmVerification(string phonenumber, string code) { var checkVerification = await VerificationCheckResource.CreateAsync(to : phonenumber, code : code, pathServiceSid : TwilioConfiguration.VerificationSid); if (checkVerification.Status == "approved") { return(new VerificationResult { Sid = checkVerification.Sid }); } throw new UserFriendlyException("There was an issue confirming your code. Please try again."); }
public async Task <string> CheckCode(string phone, string code) { TwilioInit(); try{ var verificationCheck = await VerificationCheckResource.CreateAsync( to : phone, code : code, pathServiceSid : "VA4ecd8e6e80f84392b619552df9a6ed47" ); return(verificationCheck.Status); }catch { return("Error"); } }
public void TestEmailVerificationChecksResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.Created, "{\"sid\": \"VEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"service_sid\": \"VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"to\": \"[email protected]\",\"channel\": \"email\",\"status\": \"approved\",\"valid\": true,\"amount\": null,\"payee\": null,\"date_created\": \"2020-01-30T20:00:00Z\",\"date_updated\": \"2020-01-30T20:00:00Z\"}" )); var response = VerificationCheckResource.Create("VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "code", client: twilioRestClient); Assert.NotNull(response); }
public void TestVerificationChecksResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.Created, "{\"sid\": \"VEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"service_sid\": \"VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"to\": \"+14159373912\",\"channel\": \"sms\",\"status\": \"approved\",\"valid\": false,\"date_created\": \"2015-07-30T20:00:00Z\",\"date_updated\": \"2015-07-30T20:00:00Z\"}" )); var response = VerificationCheckResource.Create("VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "Code", client: twilioRestClient); Assert.NotNull(response); }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var verificationCheck = VerificationCheckResource.Create( code: "Code", pathServiceSid: "VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ); Console.WriteLine(verificationCheck.Sid); }
public bool VerifyUserToken(string accSid, string accToken, string serviceSid, string code, string number) { string accountSid = accSid; string authToken = accToken; TwilioClient.Init(accountSid, authToken); var verificationCheck = VerificationCheckResource.Create( to: number, code: code, pathServiceSid: serviceSid ); return(verificationCheck.Status == "approved"); }
public async Task <IActionResult> OnPostAsync() { await this.LoadPhoneNumber(); if (!this.ModelState.IsValid) { return(this.Page()); } try { var verification = await VerificationCheckResource.CreateAsync( to : $"{this.CountryCode}{this.PhoneNumber}", code : this.VerificationCode, pathServiceSid : this.settings.VerificationServiceSID); if (verification.Status == "approved") { var identityUser = await this.userManager.GetUserAsync(this.User); identityUser.PhoneNumberConfirmed = true; var updateResult = await this.userManager.UpdateAsync(identityUser); if (updateResult.Succeeded) { var user = this.userManager.GetUserAsync(this.HttpContext.User); return(this.Redirect($"/Profile/{user.Result.UserName}")); } else { this.ModelState.AddModelError(string.Empty, "There was an error confirming the verification code, please try again"); } } else { this.ModelState.AddModelError(string.Empty, $"There was an error confirming the verification code: {verification.Status}"); } } catch (Exception) { this.ModelState.AddModelError( string.Empty, "There was an error confirming the code, please check the verification code is correct and try again"); } return(this.Page()); }
public async Task <IActionResult> PostVerifyPhoneCodeAsync(SMSVerification input) { await LoadPhoneNumber(); if (!ModelState.IsValid) { return(View("ConfirmPhone", input)); } try { VerificationCheckResource verification = await VerificationCheckResource.CreateAsync( to : PhoneNumber, code : input.VerificationCode, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { var identityUser = await _userManager.GetUserAsync(User); identityUser.PhoneNumberConfirmed = true; var updateResult = await _userManager.UpdateAsync(identityUser); if (updateResult.Succeeded) { ViewBag.urlAppWeb = _configuration["URLAppWeb"]; return(View("ConfirmPhoneSuccess")); } else { ModelState.AddModelError("", "Erreur lors de la vérification du code, Veuillez reessayer"); } } else { ModelState.AddModelError("", $"Erreur lors de la vérification du code: {verification.Status}"); } } catch (Exception) { ModelState.AddModelError("", "Erreur lors de la vérification, vérifiez que votre code est correct et reessayez"); } return(View("ConfirmPhone", input)); }
public async Task <IActionResult> PostVerifyPhoneCodeAsync(SMSVerification input) { await LoadPhoneNumber(); if (!ModelState.IsValid) { return(View("ConfirmPhone", input)); } try { VerificationCheckResource verification = await VerificationCheckResource.CreateAsync( to : PhoneNumber, code : input.VerificationCode, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { var identityUser = await _userManager.GetUserAsync(User); identityUser.PhoneNumberConfirmed = true; var updateResult = await _userManager.UpdateAsync(identityUser); if (updateResult.Succeeded) { return(View("ConfirmPhoneSuccess")); } else { ModelState.AddModelError("", "There was an error confirming the verification code, please try again"); } } else { ModelState.AddModelError("", $"There was an error confirming the verification code: {verification.Status}"); } } catch (Exception) { ModelState.AddModelError("", "There was an error confirming the code, please check the verification code is correct and try again"); } return(View("ConfirmPhone", input)); }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console // DANGER! This is insecure. See http://twil.io/secure const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var verificationCheck = VerificationCheckResource.Create( to: "+14159373912", code: "1234", pathServiceSid: "VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ); Console.WriteLine(verificationCheck.Sid); }
public async Task <IActionResult> OnPostAsync() { await LoadPhoneNumber(); if (!ModelState.IsValid) { return(Page()); } try { var verification = await VerificationCheckResource.CreateAsync( to : PhoneNumber, code : VerificationCode, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { var applicationUser = await _userManager.GetUserAsync(User); applicationUser.PhoneNumberConfirmed = true; var updateResult = await _userManager.UpdateAsync(applicationUser); if (updateResult.Succeeded) { return(RedirectToPage("ConfirmPhoneSuccess")); } else { ModelState.AddModelError(string.Empty, "There was an error confirming the verification code, please try again"); } } else { ModelState.AddModelError(string.Empty, $"There was an error confirming the verification code: {verification.Status}"); } } catch (Exception) { ModelState.AddModelError("", "There was an error confirming the code, please check the verification code is correct and try again"); } return(Page()); }
//注册按钮 Sign Up void Handle_Next(object sender, EventArgs e) { if (_contactNo.Remove(3) == "+86") { if (CodeEntry.Text == Settings.ChinaVerify) { Navigation.PushAsync(new SignUpPasswordPage(_contactNo)); } else { DisplayAlert("Notice", "Please check your text code and make sure it's correct. ", "OK"); } } else { try { string accountSid = Crosshelper.Properties.Resources.TWILIO_TOKEN; string authToken = Crosshelper.Properties.Resources.TWILIO_KEY; TwilioClient.Init(accountSid, authToken); var verificationCheck = VerificationCheckResource.Create( to: _contactNo, //"+14159373912", code: CodeEntry.Text, //"123456", pathServiceSid: Crosshelper.Properties.Resources.TWILIO_SERVICEID ); Console.WriteLine(verificationCheck.Status); if (CodeEntry.Text == null || verificationCheck.Status != "approved") { DisplayAlert("Notice", "Please check your text code and make sure it's correct. ", "OK"); } else { Navigation.PushAsync(new SignUpPasswordPage(_contactNo)); } } catch (Exception ex) { throw ex; } } }
public string CheckVerificationCode(int countryCode, string phoneNumber, string verificationCode) { if (!_options.TwiloEnabled) { return("NoEnabled"); } TwilioClient.Init(_options.AccountSid, _options.AuthToken); string To = "+" + countryCode + phoneNumber; var verificationCheck = VerificationCheckResource.Create( to: To, code: verificationCode, pathServiceSid: _options.VerifyServiceSid ); return(verificationCheck.Status); }
public bool?verify(string codeverifi) { try { var verificationCheck = VerificationCheckResource.Create( // to: "+2001094869002", to: _PhoneNumber, code: codeverifi, pathServiceSid: "VA9d1daf8b5346fb512d19ce6da276ca23" ); return(verificationCheck.Valid); } catch (Exception e) { return(false); } }
public async Task <IActionResult> ConfirmPhone(ConfirmPhoneViewModel confirmPhoneViewModel) { if (ModelState.IsValid) { try { var verification = await VerificationCheckResource.CreateAsync( to : confirmPhoneViewModel.PhoneNumber, code : confirmPhoneViewModel.VerificationCode, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { var identityUser = await _userManager.GetUserAsync(User); identityUser.PhoneNumberConfirmed = true; var updateResult = await _userManager.UpdateAsync(identityUser); if (updateResult.Succeeded) { return(RedirectToAction("ConfirmPhoneSuccess")); } else { ModelState.AddModelError("", "There was an error confirming the verification code, please try again"); } } else { ModelState.AddModelError("", $"There was an error confirming the verification code: {verification.Status}"); } } catch (Exception) { ModelState.AddModelError("", "There was an error confirming the code, please check the verification code is correct and try again"); } } return(View(confirmPhoneViewModel)); }
public void TestCreateRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Post, Twilio.Rest.Domain.Preview, "/Verification/Services/VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/VerificationCheck", "" ); request.AddPostParam("Code", Serialize("Code")); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { VerificationCheckResource.Create("VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "Code", client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }
public async Task <bool> VerifyPhoneNumber(string phoneNumber, string code) { try { var verification = await VerificationCheckResource.CreateAsync( to : phoneNumber, code : code, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { return(true); } return(false); } catch { return(false); } }
public async Task <bool> VerifyPhoneNumber(string phonenumber, string token) { try { var verification = await VerificationCheckResource.CreateAsync( to : phonenumber, code : token, pathServiceSid : _config.GetSection("Twilio:VerificationServiceSID")?.Value ); if (verification.Status == "approved") { return(true); } return(false); } catch (Exception ex) { return(false); } }
public async Task <IActionResult> verify([FromBody] VerifyUserResource verifyUserResource) { if (!ModelState.IsValid) { return(BadRequest(0)); } var user = await userManager.FindByNameAsync(verifyUserResource.UserName); try { var verification = await VerificationCheckResource.CreateAsync( to : "+2" + verifyUserResource.Phone, code : verifyUserResource.OTP, pathServiceSid : config["Twilio:VerificationServiceSID"] ); if (verification.Status == "approved") { user.PhoneNumberConfirmed = true; await userManager.UpdateAsync(user); var tokenString = GenerateJSONWebToken(user); return(Ok(new { token = tokenString })); } else { return(BadRequest(new APIResponse { bit = false })); } } catch (Exception ex) { return(BadRequest(new APIResponse { bit = false })); } }
public async Task <IActionResult> CheckVerificationCode(string studentId, string code) { var student = await _context.Users.FindAsync(studentId); if (student == null) { return(BadRequest()); } if (string.IsNullOrEmpty(code)) { return(BadRequest("wrongCode")); } var name = $"{student.FirstName} {student.LastName}"; var email = student.Email; try { var verification = await VerificationCheckResource.CreateAsync( to : $"{student.PhoneCode}{student.PhoneNumber}", code : code, pathServiceSid : StaticInformation.TwilioVerificationServiceSid ); if (verification.Status != "approved") { return(BadRequest("wrongCode")); } return(Ok(new { name, email })); } catch (Exception e) { Console.WriteLine(e.Message); } return(BadRequest()); }