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.
Overview
Authenticating users using Trusted Devices with Cotter's Android SDK consists of the following steps:
Import and Initialize Cotter
Calling functions to register devices a Trusted Device
Calling functions to authenticate from Trusted and Non-Trusted Device
What you're building

Steps
Set Allowed Methods in the Dashboard to allow Trusted Devices
Create a User: Create a user in Cotter by specifying your user ID.
Step 1: Import Cotter as a dependency
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.
Step 2: Setting Authentication Methods
You need to set allowed methods for authenticating your users. To allow TRUSTED DEVICES
, go to https://dev.cotter.app/rules

Remember to set the correct Project in the dropdown list
Step 3: Creating a User
To use Cotter's sign in with device functionality, you need to first register the user to Cotter.
Registering a User to Cotter
Your server should do this request to Cotter's server during Registration.
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'
Check out Create a User API Reference for full Description
Step 4: Initialize Cotter
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:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
Cotter.init(
this.getApplicationContext(),
"https://www.cotter.app/api/v0",
"[email protected]",
"<API_KEY_ID>",
"<API_SECRET_KEY>");
}
...
Step 5: Register this device as a Registered Device
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:
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();
}
});