Verify Twitter Digits Session with PHP Laravel on Android

Sharing is caring...Share on FacebookShare on Google+Tweet about this on TwitterShare on RedditEmail this to someone
digits verification step by step

digits verification step by step

0 – Introduction about Fabric & Digits

Twitter announced their Fabric SDK which includes a very interesting service called Digits. Digits allow you to verify a user registration or login via their phone number. Which proves to be a very practical. secure and fast way to authenticate users (specially on mobile). Digits actually handles sending SMS and verification of the codes sent. It currently operates in 200+ countries and 30+ languages.

 1 – Get Current Digits Session

Once a successful SMS verification code has been inserted by the user, the AuthCallback.success method is called, see the following snippet:

2 – Send tokens to server to verify  user login/registration

This should print something similar:

I/digits﹕ X-Auth-Service-Provider – https://api.digits.com/1.1/sdk/account.json
I/digits﹕ X-Verify-Credentials-Authorization – OAuth oauth_consumer_key=”wHLkT3Z0GiZjWjRbWiopLNW1q”, oauth_nonce=”747094018211629071040851137437457″, oauth_signature=”wdp1vMhafZUYTU%2FMtYjj%2Bc4In2U%3D”, oauth_signature_method=”HMAC-SHA1″, oauth_timestamp=”1437377420″, oauth_token=”3381122110-0YrghJ3EY2PIjEVK8SEmZM7UZ3wnMpexwJTFaVT”, oauth_version=”1.0″

Note: use any network library to send those values to the server; Volley, OkHttp or even HttpsURLConnection

 

3 – Server to verify tokens sent from mobile on server

via CURL:

 

via PHP:

 

FAQs:

  1. Don’t have access to session object?
    • Use the following line instead:

You’ve any questions, please leave them in the comment section below.

 

Comments ( 9 )

  1. / ReplySimon
    Hello, Thank you so much for this. I was looking to do something similar and you have just saved me a lot of time.
  2. / Replytrepatudo
    There is no curl_exec($curl) before the curl_getinfo($curl); which makes it return false everytime as you don't make the request.
    • / Replymostafazh
      Thanks a lot, I've already updated the post.
  3. / ReplyWilliamsak
    Im obliged for the article.Really thank you! Great. Stuhr
  4. / ReplyMohamed Elsaeed
    Excellent. This helped me a lot thanks Moustafa.
  5. / Replyselva.
    Phone mu,ber is not return can you tell me,where can i get..
  6. / ReplyRavi
    I was searching for this code for hours. function twitterVerifyAuth($provider, $auth) { $curl = curl_init(); curl_setopt($curl,CURLOPT_URL, $provider); curl_setopt($curl,CURLOPT_HTTPHEADER, array( 'Content-length: 0', 'Content-type: application/json', 'Authorization: '.$auth, )); curl_exec($curl); $info = curl_getinfo($curl); curl_close($curl); return $info['http_code'] == 200; } Thankyou
  7. / ReplyOOOВалок_Сидор
    RE:Verify Twitter Digits Session with PHP Laravel on Android - Mostafa's Blog НПП Валок Ролики печей цемзаводов
  8. / Replyashuthinks@gmail.com
    How Twitter digits will work with Asp.net Webapi? I'm creating web api using c# code and I want to use twitter digit service + oauth to authenticate request?

Leave a reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>