Sign In with Email/Phone Number

Our Android SDK offers the easiest way to verify email/phone numbers in your android app. You can simply call a function and it does most of the heavy lifting and authentication for you.

Concepts: Learn about how Sign in with Email/Phone Number works.

Overview

Verifying email and phone number in your mobile app using our Android SDK consists of the following steps:

  1. Import Cotter

  2. Call Cotter's Login function

  3. Receive user's email or phone number, and whether or not it's verified

What you're building

Cotter's Android SDK

Steps

  1. Register URL Scheme: Cotter's authentication will redirect back to your application using this URL scheme.

  2. Call Cotter's Login function: This function will handle the WebView, verifying phone number or email, and request the identity from Cotter's server.

  3. Receive the Token: Include the returned token and email/phone number in your server

Step 1: Import Cotter as a dependency

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.

Step 2: Initialize Cotter with your API keys

Initialize Cotter with your API_KEY_ID . Call the function below in your MainActivity

For example:

Step 3: Register a URL Scheme

You also need to decide a callback URL scheme that you want to use. If your app's package name is com.example.myapplication then you should use something like this for your URL Scheme callback.

This URL scheme will be called when Cotter's verification is done and want to go back to your app. Read more about Android deep-linking.

You need to register this URL Scheme to receive the callback. Add the following in your AndroidManifest.xml . Check the example in the example's Github repo.

Step 4: Call Cotter's Login function

To open up Cotter's Login screen, you can either have your user input their email or phone number inside Cotter's screen, or you can provide a text input where your users can enter their email / phone, and you can pass that to Cotter's screen.

a) To login and enter the email or phone number in Cotter's window:

b) To login with the email or phone number that your user entered in your app:

To send code/link via SMS or WhatsApp, you'll need to add some balance to you project in the Dashboard.

You need to provide a class to redirect to when Cotter's email/phone number verification is complete.

Step 5: Receive the Token

In your CallbackActivity class, receive the token from the intent inside onCreate using this function.

For example, if your CallbackActivity class is called Dashboard:

The resp will consist of the following JSON Object as a string.

This JSON object contains 3 objects, identifier , oauth_token and user .

  • The identifier object contains information about the user's email or phone number, device type and name, and expiry.

  • The oauth_token contains an access_token that you can validate in your backend.

  • The user contains the User object in Cotter, which includes a "Cotter User ID". You should associate your user with this Cotter User ID for reference.

Validating Cotter's Access Token

Checkout how to verify the OAuth Tokens from Cotter here:

Verifying JWT Tokens

πŸŽ‰ You're done!

Securing your Project

Since you'll be using your API Key from a front-end website or mobile app, your API_KEY_ID is exposed to anyone inspecting your code. Here are some ways to prevent abuse:

Next Steps

Implement Trusted Devices

Sign In with Device

Add Biometric/PIN

Biometric/Pin

Last updated