Skip to main content
Version: v6

Secure and frictionless device change

The section on protecting app logins explains how to use Incognia more broadly to improve the recognition of trusted users at login without adding friction to the user experience. However, there are several specific high-risk authentication scenarios where MFA is always required and traditional factors and authentication controls are very high friction for users. One such scenario is device change. New devices authenticating to known accounts are a challenge because it may be an attacker trying to take over a compromised account or a legitimate user who simply bought a new phone. Because it's traditionally been difficult to distinguish between a good and bad device change, organizations have been forced to increase authentication friction and limit app functionality on the new device prior to completing MFA for all users, legitimate or otherwise.

With Incognia’s layered location behavior and device intelligence solution, your organization can identify new devices, silently authenticate good users based on their Trusted Locations, and block compromised account access using Location Behavior and Device Reputation (see the section on understanding risk assessments).

In this how-to, you will learn how to integrate the Incognia Transaction API to automatically authenticate trusted login attempts coming from new devices with no added friction, trigger step-up authentication when necessary, and block suspicious logins.

Requirements

Step-by-step

Setting the Account ID

In order to allow the detection of permanent logins, Incognia needs to have an association between a device and a unique account identifier. The Account ID is used for this purpose.

important
This step is the basis for the first login detection, which will be handled by your server later on as explained in the section that covers handling the user's first login request

This association must happen in two moments:

1. Whenever the application initializes

This covers the scenario where the application is updated with the Incognia SDK and the user is already logged in. The Application.onCreate() on Android or the [AppDelegate application:didFinishLaunchingWithOptions:] on iOS are good places to do this.

If the Account Id is not available in those locations, it is important to forward the value to the Incognia SDK as soon as it is available. The important action here is to call setAccountId whenever the application initializes so it is guaranteed that we always know that a specific user is associated with a specific device.

2. Whenever the user logs in and out

It is necessary to call the setAccountId method when the user finishes the login and clearAccountId when the user logs out. This is usually done in the callback of these two actions.

tip
The setAccountId method can be called multiple times by the same user with no performance impact.
// Set the Account ID
Incognia.setAccountId(accountId)

warning
While data such as e-mail and phone numbers are examples of identifiers, their use in the SDK is forbidden. Consider using non-personal information, such as UUIDs, and Hashing to securely generate and set the Account ID.

Forwarding the device's Installation ID to your server

To verify a login attempt, Incognia needs to receive an Installation ID to identify the device from which the login originates. Since your server will request the Incognia API to assess the risk of this login, it needs to receive this information from your mobile application.

The installation ID can be forwarded to your server in two ways.

Option 1: Sending the Installation ID as a header

Before sending a login request from your mobile application to your server, call Incognia.getInstallationId and set its value as a header of the request. Choose a clear name for this header, like Incognia-Installation-ID, so you can easily identify it on the server-side.

This option has a clear benefit if your application will use more than one Incognia solution because you won't need to change each request's properties, like signup, login, payment, password change, etc.

// This method may return null if the SDK has not yet been initialized or if an error occurs on initialization.
val installationId = Incognia.getInstallationId()

// HttpURLConnection
httpUrlConnection.setRequestProperty("Incognia-Installation-ID", installationId)

// Send the request with the installationId to your backend server

Option 2: Sending the Installation ID in the body of the request

Before sending the login request from your mobile application to your server, call Incognia.getInstallationId and send it as additional information about this login. Choose a clear name for this property like Incognia-Installation-ID, so you can easily identify it on the server-side.

Handling the user's first login request

When your server receives a login request, you can use Incognia intelligence to identify first login attempts from a new device and assess the risk inside this request/response cycle. This is possible because you set the Account ID in previous step (Setting the Account ID on the app).

To evaluate this login attempt risk, your server will request the Login Transaction API informing that a login attempt was made alongside its Installation ID and the Account ID of the account that the device is attempting to access.

A sample implementation of a controller/handler

Let's consider a toy example as back-end with the controller below:

// LoginController.java
@Controller("/login")
public class LoginController {
private final PasswordAuthenticator passwordAuthenticator;
private final TokenGenerator tokenGenerator;

@Post
public HttpResponse<?> postLogin(@Valid @Body LoginRequest request) {
boolean isPasswordValid = passwordAuthenticator.isValid(request.getEmail(), request.getPassword());
if (isPasswordValid) {
Token token = tokenGenerator.getTokenForUser(request.getEmail());
return HttpResponse.ok(token);
}
return HttpResponse.unauthorized();
}
}
important
You are required to authenticate when using the Incognia API. For authentication details, see Authenticating in Incognia APIs

Considering that the authentication logic is implemented, you can add risk assessment requests to your login handler:

// LoginController.java
@Controller("/login")
public class LoginController {
private final PasswordAuthenticator passwordAuthenticator;
private final TokenGenerator tokenGenerator;
// read how to use Incognia's Java Wrapper: https://github.com/inloco/incognia-api-java
private final IncogniaAPI incogniaAPI;

@Post
public HttpResponse<?> postLogin(@Valid @Body LoginRequest request) {
boolean isPasswordValid = passwordAuthenticator.isValid(request.getEmail(), request.getPassword());

if (!isPasswordValid) {
return HttpResponse.unauthorized();
}

RegisterLoginRequest incogniaRequest =
RegisterLoginRequest.builder()
.installationId(request.getIncogniaInstallationId())
.accountId(request.getAccountId())
.evaluateTransaction(true)
.build();
TransactionAssessment transactionAssessment = incogniaAPI.registerLogin(incogniaRequest);

Assessment riskAssessment = transactionAssessment.getRiskAssessment();
Boolean isFirstDeviceLogin = transactionAssessment.getEvidence().get("first_device_login");

if (isFirstDeviceLogin) {
if (riskAssessment.equals(Assessment.HIGH_RISK)) {
// Automatically denies if Incognia gives high risk!
return HttpResponse.unauthorized();
}

else if (riskAssessment.equals(Assessment.UNKNOWN_RISK)){
// Trigger step-up authentication if Incognia gives unknown risk.
return HttpResponse.forbidden();
}
}
else {
// Handle common login attempts
}
}
}

Deployment considerations

Incognia relies on the relation between a device and a unique account identifier to identify new devices authenticating to known accounts. When you call Incognia.setAccountId on your app (as detailed in Setting the Account ID on the app) the link between account and device is made and the first_device_login evidence it is set to true only for actual unknown devices. To avoid considering your logged in users and their devices as device changes (new devices), you need to roll out the app before starting calling the API as follows:

1. Release the app integrated with Incognia SDK

Every authenticated user will call Incognia.setAccountId.

2. Give time to Incognia know your account's identifiers and devices

Over time Incognia will receive the SDK events and have the devices linked with your unique account identifier. You need to monitor the percentage of your users with the SDK and the percentage of active installs with Account ID. When the first reaches 100% and the second stabilizes the growth curve, you can move forward and release the server integrated with Incognia.

For example, the image below shows metrics of an app that was released recently and did not reached the needed stability regarding the % of active installs with Account ID. This second image shows metrics of an app that reached the stability and the server can be released. See how to monitor the percentage of active installs with Account ID at Incognia App metrics dashboard.

3. Release the server integrated with Incognia Login Transaction API

Your server will start calling Incognia Login Transaction API that will identify only new devices authenticating to known accounts as first login attempts.

important
What about persistent sessions?

If your app has persistent sessions, it is possible that Incognia.setAccountId will be called only when the user logs out and logs in again. This can increase the time necessary to Incognia know your account's identifiers and devices, and it is also influenced by the length of your app user session. To circumvent this, you can force the termination of your user’s session.

Using the Incognia risk assessment

When your server makes a request to the Transaction API endpoint, it will receive a response like the following:

{
"id": "96fafbb9-93af-433a-b047-af1f6fc3c279",
"risk_assessment": "low_risk",
"reasons": [
{
"code": "trusted_location",
"source": "local"
}
],
"evidence": {
"device_model": "LM-X520",
"known_account": true,
"location_services": {
"location_permission_enabled": true,
"location_sensors_enabled": true
},
"device_integrity": {
"probable_root": false,
"emulator": false,
"gps_spoofing": false,
"from_official_store": true
},
"device_fraud_reputation": "unknown",
"device_behavior_reputation": "unknown",
"distance_to_trusted_location": 3.4356838410826773,
"last_location_ts": "2022-04-25T13:33:54.285Z",
"sensor_match_type": "wifi_connection",
"account_integrity": {
"recent_high_risk_assessment": false
},
"accessed_accounts": 1,
"app_reinstallations": 1,
"first_device_login_at": "2022-04-20T12:28:44.433318Z",
"first_device_login": false
},
"device_id": "dOgLG4Sm8wRIeyWRyl_-ty-ofSXgZOCACnx1w7T4JLeQAOgRt_7trL24yGmfU5JSR1JEZMAzG-JOtXNFhT3h2A"
}

The response contains the id of the created entity (in this case, a login), the risk_assessment provided by Incognia based on device behavior, and evidence that supports this assessment. You can learn more about all the returned data in this article: Understanding risk assessments.

The returned assessment can be used with other risk-related data, such as in a risk engine, to decide if this login attempt should be accepted.

The first_device_login evidence indicates if this is the first time that the given device is bind with the given account, you can use this evidence to handle this kind of login attempt differently. It can be used together with Incognia's risk assessments as detailed below:

  • First login assessed as high_risk: the login performed by the new device may be fraudulent and we advise you to take preventive actions in these scenarios, such as requiring additional step-up authentication or simply blocking this login attempt;
  • First login assessed as low_risk: the login performed by the new device seems to be safe to accept;
  • First login assessed as unknown_risk: we are unable to provide a precise assessment at the time of the request. You should require additional authentication (e.g. 2FA).

Wrapping Up

After these steps, your application is ready to recognize trusted users at device change without friction and preventing account takeovers.