Comment on page
Sign In with Device
Our Android SDK offers the easiest way to integrate "Sign in with device" to your android app. You can simply call a function and it does most of the heavy lifting and authentication for you.
Authenticating users using Trusted Devices with Cotter's Android SDK consists of the following steps:
- 1.Import and Initialize Cotter
- 2.Calling functions to register devices a Trusted Device
- 3.Calling functions to authenticate from Trusted and Non-Trusted Device

Trusted Devices on Cotter's Android SDK
- 2.
- 3.
Add JitPack repository your project level
build.gradle
at the end of repositories.allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the Cotter's SDK as a dependency in your app level
build.gradle
.android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
...
implementation 'com.github.cotterapp:android-sdk:0.3.9'
}
Check the latest version here https://github.com/cotterapp/android-sdk/releases. Then sync your gradle files.
You need to set allowed methods for authenticating your users. To allow
TRUSTED DEVICES
, go to https://dev.cotter.app/rules
Set Trusted Device as an Allowed Method
Remember to set the correct Project in the dropdown list
To use Cotter's sign in with device functionality, you need to first register the user to Cotter.
Your server should do this request to Cotter's server during Registration.
Request
Response
curl -XPOST \
-H 'API_KEY_ID: <your key id>' \
-H 'API_SECRET_KEY: <your secret key>' \
-H "Content-Type: application/json" \
-d '{"client_user_id": "<Your User Identifier (string)>"}' \
'https://www.cotter.app/api/v0/user/create'
{
"ID": "9449e9e9-00e0-4d6b-a4b6-28c5b22b0b0f",
"created_at": "2020-01-21T12:40:21.200727668Z",
"update_at": "2020-01-21T12:40:21.200727668Z",
"deleted_at": null,
"issuer": "<your key ID>",
"client_user_id": "<Your User Identifier (string)>",
"enrolled": [],
"default_method": null
}
You can now use the SDK to enroll and verify Trusted Devices for the user you just created.
In your MainActivity, initialize Cotter with API keys, Cotter's URL to use (prod/test), and your User ID.
Production Endpoint:
https://www.cotter.app/api/v0
Cotter.init(
this.getApplicationContext(),
"https://www.cotter.app/api/v0",
"<User ID>", // fill with empty string for Verify EMAIL & PHONE
"<API_KEY_ID>",
"<API_SECRET_KEY>" // fill with empty string for Verify EMAIL & PHONE
);
Example:
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
Cotter.init(
this.getApplicationContext(),
"https://www.cotter.app/api/v0",
"<API_KEY_ID>",
"<API_SECRET_KEY>");
}
...
Right after your user finished their registration to your app, you should automatically register the device as a Trusted Device (or prompt your user if they want to make this device as a Trusted Device).
To enroll the current device as a TrustedDevice:
Java
JSON result
TrustedDeviceHelper.enrollDevice(this, new Callback() {
@Override
public void onSuccess(JSONObject result) {
Toast.makeText(getApplicationContext(), result.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onError(String error) {
Toast.makeText(getApplicationContext(), error, Toast.LENGTH_SHORT).show();
}
});
{
"ID": "746500ae-a5cd-4692-8fd0-49d57cf7cc57", // User ID from Cotter's system
"created_at": "2020-02-25T04:08:26.174597Z",
"update_at": "2020-02-27T22:20:31.333154814Z",
"deleted_at": null,
"issuer": "afcabd98-745f-4b9e-98de-af968d9951d3", // your API KEY ID
"client_user_id": "1014", // you client's user ID
"enrolled": [ // Enrolled Authentication Methods
"PIN",
"BIOMETRIC",
"TRUSTED_DEVICE" // This should be added to enrolled methods once enrollDevice successful
],
"default_method": "TRUSTED_DEVICE" // This will automatically be the last enrolled method, which is Trusted Device in this case
}