Get Started with PhoneCheck on Mobile Web

Get Started with Mobile Web

This Guide will walk you through performing your first PhoneCheck within a Mobile Web application using a Node.js server. It covers:

The mobile web example application comes bundled with the Node.js example server so the final application structure looks as follows:

└── phonecheck-server
└── tru.json

And the running Mobile Web application looks and works as follows:

phone device wrapper

For more detailed information on how the mobile application, the Node.js server and the tru.ID APIs work together see the PhoneCheck Integration guide.


PhoneCheck verifications are achieved by making an authenticated web request over a device's mobile data connection. You can programmatically instruct a web request to go over the mobile data connection on a native application. However, you cannot do this within a web browser so you must first detect if the device is connected to WiFi and if not ask the user to disable WiFi.

1. Before you begin

In order to execute a PhoneCheck you'll need a physical mobile device with a web browser that has an active mobile data connection.

To expose the locally running Node.js server to the running mobile application you'll require a local tunnel solution such as ngrok.

To run through the guide as a whole you'll need a tru.ID account. If you don't already have an account, sign up now.The tru.ID tooling relies on the Node.js runtime. So please ensure you have the Node.js runtime installed.

Install and setup the tru.ID CLI

With Node.js install the tru.ID CLI (Command Line Interface) from your terminal.
$ npm install -g @tru_id/cli
After the installation you should setup the CLI with your tru.ID Default Credentials. These can be found within the tru.ID Console.
$ tru setup:credentials {YOUR_CLIENT_ID} {YOUR_CLIENT_SECRET} EU

Create a working directory

Create a directory that you will add the client and server example code to:

$ mkdir tru-id-phonecheck-example

And navigate into that directory:

$ cd tru-id-phonecheck-example

2. Setup the Node.js example server

The Node.js example server is used as an authority and sits between the Mobile Web application and the tru.ID APIs.

Clone the Node.js Server Example

Clone the tru.ID Node.js example server into thephonecheck-server directory:

$ git clone phonecheck-server

Create a tru.ID project

Create a new tru.ID project and save the configuration to the phonecheck-server directory:

$ tru projects:create "phonecheck-server" --project-dir=phonecheck-server

You will see output similar to the following:

Creating Project "phonecheck-server"
Project configuration saved to "path_to/tru-id-phonecheck-example/phonecheck-server/tru.json"

The Node.js application will read your credentials from the tru.json project configuration file.

Run the tru.ID example server

Navigate into the phonecheck-server directory:

$ cd phonecheck-server

Install the application dependencies:

$ npm install

Run the application:

$ npm start

You will see output similar to the following indicating that the server application is running at http://localhost:8080:

> tru-node-server@0.1.0 start
> nodemon src/index.js
[nodemon] 2.0.4
[nodemon] to restart at any time, enter 'rs'
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting 'node src/index.js'
project_id: '0055f3a3-6e06-4390-9048-4f5a9dfcbbd1',
name: 'phonecheck-server',
credentials: [
client_id: 'PROJECT_CLIENT_ID',
client_secret: 'PROJECT_CLIENT_SECRET',
created_at: '2021-01-11T15:44:14+0000',
scopes: [Array]
mode: 'live',
created_at: '2021-01-11T15:44:14+0000'
Example app listening at http://localhost:8080

Create a local tunnel for your server

In order for your mobile application to be able to interact with the locally running server you'll need to setup a local tunnel. For this example we'll use ngrok.

Run `ngrok` to create a local tunnel and to get a public URL which will be used in the mobile application configuration. Run the following command in a new terminal window:

$ ngrok http 8080

You will then see output similar to the following:

Session Status online
Account Phil Leggetter (Plan: Pro)
Version 2.3.35
Region United States (us)
Web Interface
Forwarding -> http://localhost:8080
Forwarding -> http://localhost:8080
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00

Navigate to your ngrok HTTPS URL to ensure the server is accessible ( from the above output).

3. Perform a PhoneCheck

Open up your mobile web browser and navigate to the public ngrok HTTPS URL.

Once the default web page has loaded, scroll down to the Example Pages and click the Mobile Web PhoneCheck link. The page that loads is the Mobile Web example application.

If you are on WiFi the application will prompt you to turn it off. Once you have WiFi disabled, enter your phone number including the country code and click "Verify my phone number". The application will look similar to the following:

phone device wrapper

With that, you've completed your first PhoneCheck from a Mobile Web application.

4. Resources

5. Troubleshooting

No troubleshooting content at this time.

Made withacross the 🌍
© 2021 4Auth Limited. All rights reserved. tru.ID is the trading name of 4Auth Limited.