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.
Last updated
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.
Last updated
Concepts: Learn about how Sign in with Device works.
There are major updates planned for this feature. Contact us in Slack so we can help you prepare for it.
Authenticating users using Trusted Devices with Cotter's Android SDK consists of the following steps:
Import and Initialize Cotter
Sign up a new user and trust the current device
Sign in existing user from a Trusted and a Non-Trusted Device
Add JitPack repository your project level build.gradle
at the end of repositories.
Add the Cotter's SDK as a dependency in your app level build.gradle
.
Check the latest version here https://github.com/cotterapp/android-sdk/releases. Then sync your gradle files.
You can now use the SDK to sign up a new user and setup the device as trusted, or sign in an existing user using the trusted device
In your MainActivity, initialize Cotter with your API_KEY_ID
. You can get it from the Dashboard.
Example:
The user should enter an identifier (an email, phone number, or username).
The SDK will register a new user with that identifier, and then enroll the current device as a Trusted Device.
This method is only for the first Trusted Device. You will get an error if you attempt to enroll another Trusted Device using enrollDevice
when there's already a Trusted Device for the account. To enroll other devices, see Add a new Trusted Device.
To authenticate a device, call the Cotter.signInWithDevice
function. This will automatically detect whether the current device is a Trusted Device or not.
identifier
: Your user's identifier (email/phone/username) that was used to register this user in Step 3.
callbackClass
: The next activity class that you want to redirect to when the authentication request is finished
callback
: A custom Callback function that implements 2 methods: onSuccess
and onError
.
When an Authentication Event is requested using method TRUSTED_DEVICE
, there are 2 possible cases:
If the current device is a Trusted Device, it should automatically be approved, and you will receive a JSON result containing the requested Event
and whether or not it's approved. The approval is based on whether or not the signature included in the request from the SDK is valid.
You should see a result that the event is not new, and that it's approved. This is because the signature from the Trusted Device is sufficient to prove that the device is authorized.
When passing this Response to your backend, you need to check if this JSON is valid and if it comes from Cotter's server by validating the access token.
Checkout how to verify the OAuth Tokens from Cotter here:
Verifying JWT TokensWe'll cover this in the next guide:
Authenticate from a Non-Trusted Device