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.
Last updated
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.
Last updated
Concepts: Learn about how Sign in with Email/Phone Number works.
Verifying email and phone number in your mobile app using our Android SDK consists of the following steps:
Import Cotter
Call Cotter's Login function
Receive user's email or phone number, and whether or not it's verified
Register URL Scheme: Cotter's authentication will redirect back to your application using this URL scheme.
Call Cotter's Login function: This function will handle the WebView, verifying phone number or email, and request the identity from Cotter's server.
Receive the Token: Include the returned token and email/phone number in your server
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.
Initialize Cotter with your API_KEY_ID
. Call the function below in your MainActivity
For example:
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.
Make sure your URL scheme (the front part before ://
) doesn't have an underscore or other special characters. To test it out, enter your Redirect URL here: https://jsfiddle.net/omd02jn5/
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.
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.
Try it now! You can check if it works so far by invoking the login function above on a button click. It should load Cotter's Authentication page on a WebView.
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.
You should include this JSON Object into your call to your backend for Login or Registration. Your backend should then verify that the access token is valid.
Checkout how to verify the OAuth Tokens from Cotter here:
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: