PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 19, 2022

[FIXED] How do I send a user token via SMS with Authy and PHP?

 November 19, 2022     authy, php, twilio, twilio-php, two-factor-authentication     No comments   

Issue

I am trying to run a demo for Authy in PHP. I have installed the Authy library with Composer, so now I can register a user using hardcoded values like this:

$authy_api = new Authy\AuthyApi('<TESTING API KEY>', 'http://sandbox-api.authy.com'); // actual key omitted -- using the key generated for testing, not the one for production

$user = $authy_api->registerUser('something@something.com', '999-999-9999', 30); // actual credentials omitted

if($user->ok()){
    echo "Success!";
    $id = $user->id();
    echo($id);  
}

When the above script runs, a 5-digit user id is indeed generated, so all seems to be going well, yet the SMS is never delivered to my phone.

One possible problem could be that my number is already registered as the app phone (associated with the admin account), so since (per the docs) each phone number has to uniquely identify a user, maybe mine was already registered for this app and therefore no need arose to send a new token. Should that be the case, the id of the user object may be the previously registered one.

The problem remains with other phone numbers however. So now I'm lost.


Solution

Turns out, there was nothing wrong with the code per se.

It's just the Sandbox API does not actually go through with sending the SMS. It only simulates the process for testing purposes, so that the authentication flow is the same as with the production API.

When I switched to production API URL and key, I was able to receive the SMS on my phone.



Answered By - Guybrush Threepwood
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing