Integrate One Tap Sign In on your website - PHP / JAVA


Introduction

One Tap Sign In is a phone verification plugin that works on the frontend, similar to Gmail - One Tap Sign in. It simplifies global phone number verification by using OTP/pass code. Sign in with Phone eliminates the need for complex telecom registration and SMS API Gateway integration for each country.

Click here to try One Tap Sign in With Phone demo .

To seamlessly integrate the plugin into your website, follow the instructions provided below.

Frequently Asked Questions

  • Very easy to integrate

  • Cost effective and reliable service

  • Save DLT registration cost (~ 5800 INR)

  • No need for sender Id registration

  • No need for SMS template approval

  • No SMS gateway required

1. Admin Dashboard

To integrate One Tap Sign In button on your website, get the CLIENT_ID from the Profile Details section by signing into the Admin Dashboard. You will need to update the Client ID in the code snippet as instructed in step 2.

Admin Dashboard link: https://admin.phone.email

phone.email

2. Integrate One Tap Sign In button

To integrate One Tap Sign In button on all pages of your website, please add the following code snippet just before closing the <body> tag.

Note - To configure the plugin, you must modify the following parameters in the code snippet above :

  • client_id: Set client id which you obtained from Profile Details section of Admin Dashboard as explained in Step 1.
  • button_text: Set button text as per your requirement.
  • logout: Possible values are "enable" or "disable".
  • redirect_url: Do not change this variable, it will be updated in next step.


<div id="pheIncludedContent"></div>
<script src="https://auth.phone.email/login_automated_v1_3.js"></script>
<script>
  var reqJson='{"client_id":"TYPE_YOUR_CLIENT_ID_HERE","button_text":"Sign in with Phone","email_icon_position":"left","logout":"enable","redirect_url":""}';
log_in_with_phone(reqJson);
</script>

3. Get verified phone number

Create a login success page (Example: https://your-domain-name/loginsuccess) on your website where user will be redirected after successful phone verification and also set this URL in redirect_url variable used in Step 2.

We will supply access_token as query parameter to this page which is required to get verified phone number as per the code snippet below.

Note

  • client_id: Set client id which you obtained from Profile Details section of Admin Dashboard as explained in Step 1.

<?php

/* After successful phone number verification an access_token will be returned by auth verification popup. In this if condition  please use this access_token to call Phone Email API to get verified phone number.  */
if(isset($_GET['access_token'])){

    /* To get verified phone number please call the getuser API */

    // Initialize cURL session
    $ch = curl_init();
    $url = "https://eapi.phone.email/getuser";
    $postData = array(
        'access_token' => $_GET['access_token'],
        'client_id' => 'TYPE_YOUR_CLIENT_ID_HERE'
    );

    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, $url); // URL to submit the POST request
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string instead of outputting it directly
    curl_setopt($ch, CURLOPT_POST, true); // Set the request type to POST
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); // Set the POST data
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Ignore SSL certificate verification (not recommended in production)

    $response = curl_exec($ch);

    if ($response === false) {
        // Handle error here
    }

    curl_close($ch);

    $json_data = json_decode($response,true);

    if($json_data['status'] != 200) {
        // Handle error here
    }

    $country_code = $json_data['country_code'];
    $phone_no = $json_data['phone_no'];

    // Register User: If user corrosponding to this verified phone number does not exist in your user table then add the user in your user table here and continue to the next step. If user already exists then skip the next step.

    // Send Email: We reccomend you to send welcome email to the user.
    //curl --location --request POST "https://api.phone.email/v1/sendmail" --ssl-no-revoke --header "Content-Type: application/json" --data-raw "{'apiKey':'API_KEY','fromCountryCode':'XXX','fromPhoneNo':'XXXXXXXXXX', 'toCountrycode':'XX','toPhoneNo':'XXXXXXXXXX','subject': 'Welcome to YOUR_BUSINESS_NAME','tinyFlag':true,'messageBody':'V2VsY29tZSB0byB5b3VyIEJVU0lORVNTX05BTUU='}"

    // Create Session: Store verified user phone number in session variable.

    // Redirect: Redirect user to the page of your choice as the user has successfully logged in.

    // Handle Logout (Optional): You can create logout button on your website as required.In the event of logout you must clear delete ph_email_jwt cookie and clear your session variables.  To delete cookie simply set it to blank -> setcookie("ph_email_jwt", "", time()-3600);
    ?>
<?php
} ?>


  

@RestController
@RequestMapping("/api")
public class PhoneVerificationController {

    private static final String CLIENT_ID = "your_client_id"; // Replace with your actual client ID
    private static final String PHONE_EMAIL_API_URL = "https://eapi.phone.email/getuser";

    @PostMapping("/get_verified_phone")
    public ResponseEntity<Map<String, Object>> getVerifiedPhone(@RequestBody Map<String, Object> requestPayload) {
        if (requestPayload.containsKey("access_token")) {
            String accessToken = requestPayload.get("access_token").toString();

            // Call the Phone Email API to get verified phone number
            RestTemplate restTemplate = new RestTemplate();
            Map<String, Object> data = new HashMap<>();
            data.put("access_token", accessToken);
            data.put("client_id", CLIENT_ID);

            try {
                Map<String, Object> response = restTemplate.postForObject(PHONE_EMAIL_API_URL, data, Map.class);

                if (response != null && response.containsKey("status") && response.get("status").equals(200)) {
                    Map<String, Object> responseBody = new HashMap<>();
                    responseBody.put("country_code", response.get("country_code"));
                    responseBody.put("phone_no", response.get("phone_no"));
                    responseBody.put("ph_email_jwt", response.get("ph_email_jwt"));

                    return ResponseEntity.ok(responseBody);
                } else {
                    return ResponseEntity.badRequest().body(Collections.singletonMap("error", "Invalid access token"));
                }
            } catch (Exception e) {
                return ResponseEntity.status(500).body(Collections.singletonMap("error", "Request failed: " + e.getMessage()));
            }
        }
        return ResponseEntity.badRequest().body(Collections.singletonMap("error", "Access token not provided"));
    }
}

4. Logout

To handle logout simply remove the cookie named ph_email_jwt as per your programming language. In addition to deleting the cookie you should also destroy any session you have created during login process. To disable logout button managed by one-tap integration simply change "logout" variable value from "enable" to "disable" in Step 2.



Should you encounter any technical challenges during the integration process, please don't hesitate to reach out to us for assistance.

Contact us WhatsApp Us