Authenticate With Firebase Using Snap’s Login Firebase Extension - Android

This extension allows your community of users to authenticate with Firebase using their Snapchat accounts. Snapchat has a massive reach, with millions of people using the app daily. Logging in via Snapchat allows you to tap into this audience, providing a quick and easy way for your users to sign up, log in, and avoid any obstacles.

Getting Started

Before you begin, you will need a Snapchat account with a verified email address. If you do not have one yet, you can create it here. Once you have obtained an account, follow the instructions below:

Google Cloud Project

In your Google Cloud project, make sure to enable the Secret Manager API.

Snapchat Developer Portal

The Developer Portal is a web interface designed for Snap Kit developers to create and manage their Projects. Using your Snapchat account, log in to the Portal.

  1. Once you have logged in, you will be prompted to create a new Organization. If you already have one, you may skip this step.
  2. Next, create a new Snap Kit Project. If you already have one, you may also skip this step.
  3. In your Project, you will find several elements that will help you build out your application. For more information on each of these elements, please refer to this guide.
  4. Under the Setup tab, you will find a section for a Staging and Production client ID. Here, generate a confidential OAuth 2.0 client ID. You may add one for Staging for testing purposes, and one for prod for Production usage. You will have one-time access to client secrets.
  5. Next, navigate back to the Secret Manager in Google Cloud.
  6. Create a secret with the value obtained in Step 4.
  7. Go back to your Snap Kit Project.
  8. Create a version and toggle Login Kit on. Configure the necessary parameters, such as the Redirect URIs for OAuth.
  9. To use the Production client, go through the review process and get your Snap Kit project approved. You can find a guide for our review guidelines here.

Firebase Project

In your Firebase Project,

  1. Enable Firebase Authentication to enable sign-up options for your users.
  2. Create a service account for your project in the Service Accounts dashboard.
  3. Give the following roles to the newly created account:
  • Cloud Functions Admin
  • Firebase Admin SDK Administrator Service Agent
  • Firebase App Check Admin
  • Firebase Authentication Admin

Install the Snap Login Firebase Extension

Once you’ve set up your Projects, you must install the Login Firebase extension. You can do this either through Firebase’s console or CLI:

Using the Firebase Console

To install the extension using the Firebase console, visit the page here.

Using the Firebase CLI

To install the extension using the Firebase CLI, run the following commands:

1npm install -g firebase-tools
1firebase ext:install snap/snapchat-login --project=projectId_or_alias

Service Account Permissions

After you have installed the extension:

  1. Navigate to the Functions section in your Firebase project. You will see a list of Cloud Functions deployed.
  2. Then, navigate to the Detailed Usage Stats of the getCustomToken Cloud Function.
  3. Select Details.
  4. Assign Service Account Token Creator and Secret Manager Secret Accessor IAM roles to the service account that you see.

Android Project

In your Android project, if you haven’t already, add Firebase. Detailed instructions are highlighted in this page.

  1. Once you’ve done this, update your root-level build.gradle with the following dependency (for more information, please refer to our Login Kit guide):

root-level build.gradle

1repositories {
2   maven {
3       url ""
4   }
  1. Then, update your app-level build.gradle with following dependencies:
  • Add the following Snap Kit dependencies (for more information, please refer to our Login Kit guide):

    app-level build.gradle

    1def snapKitVersion = "1.11.0"
    3dependencies {
    4    . . .
    5    implementation ([
    6        "com.snapchat.kit.sdk:core:$snapKitVersion",
    7        "com.snapchat.kit.sdk:login:$snapKitVersion",
    8    ])
  • Include the relevant Firebase Auth dependencies.

  1. Update your AndroidManifest.xml with the following (most instructions can be found in our Login Kit guide, aside from the Firebase Custom Token metadata flag, which is highlighted below):


1.  .  .
3<uses-permission android:name="android.permission.INTERNET" />
5<!-- TODO(1): Declare the Snapchat package query
6     (required only if your app targets Android 11 (API 30) or higher)
10  <package android:name="" />
13<application ...>
15    <!--  TODO(2) Insert Confidential OAuth2 Client ID from Snap Kit
16          Developer Portal !-->
18    <!--
19        Make sure that in the Snap Kit Developer Portal:
20        1. You set your app's Android App ID under the "Platform Identifiers"
21           section.
22        2. Your Snapchat username is in the list of "Demo Users" (only
23           required if testing on the Staging).
24        3. Click Generate for "Confidential OAuth 2.0 Client ID".
26        Then you should paste your Staging/Production Confidential OAuth2 Client
27        ID here.
28    -->
30    <!--
31        You can use the Staging Client ID anytime, even before an app is
32        reviewed and approved. However, only accounts listed under the
33        "Demo Users" on the Snap Kit Developer Portal will be able to use
34        your application.
35    -->
37    <!--
38        With the Production Client ID, your app can post the content from
39        any Snapchat account. However, your app must be approved for the
40        Production Client ID to work.
41    -->
43    <meta-data
44        android:name="com.snapchat.kit.sdk.clientId"
45        android:value="INSERT_CONFIDENTIAL_OAUTH2_CLIENT_ID" />
47    <!--  TODO(3) Declare the redirect url that will handle and complete
48          login requests !-->
50    <!--
51        Make sure that in the Snap Kit Developer Portal:
52        1. You add this url in the "Redirect URIs for OAuth" section
53    -->
55    <!--
56        The redirect URL itself doesn't need to have any meaning associated
57        with it and in general, the only real criteria would be to pick a
58        URL with a scheme that is unlikely to collide with a scheme of
59        another app.
61        The URL should however follow the syntax "foo://bar".
62        If you need ideas, you could try "myapp://snap-kit/oauth2".
63    -->
64    <meta-data
65        android:name="com.snapchat.kit.sdk.redirectUrl"
66        android:value="INSERT_URL_TO_HANDLE_LOGIN_COMPLETION" />
68    <!-- TODO(4) Declare the resources that you want to request -->
70    <!--
71        You'll have to define ‘snap_connect_scopes’ as an Android resource
72        array in ‘res/values/arrays.xml’
73    -->
74    <meta-data
75        android:name="com.snapchat.kit.sdk.scopes"
76        android:resource="@array/snap_connect_scopes" />
78   <!--  TODO(5) Specify the full URL to the Firebase Extension
79         resource !-->
81   <!--  You should get this after you install the Firebase Extension !-->
82   <meta-data
83       android:name="com.snapchat.kit.sdk.firebaseExtCustomTokenUrl"
84       android:value="INSERT_FIREBASE_CUSTOM_TOKEN_URL" />
86   ...
88   <!--  TODO(6) Declare the SnapKitActivity that will handle the deeplink
89         response from Snapchat !-->
91   <activity
92       android:name="com.snapchat.kit.sdk.SnapKitActivity"
93       android:launchMode="singleTask"
94       >
95       <intent-filter>
96           <action android:name="android.intent.action.VIEW" />
97           <category android:name="android.intent.category.DEFAULT" />
98           <category android:name="android.intent.category.BROWSABLE" />
99           <!--
100               Enter the parts of your redirect url below
101               e.g., if your redirect url is myapp://snap-kit/oauth2
102                   android:scheme="myapp"
103                   android:host="snap-kit"
104                   android:path="/oauth2"
105           !-->
106           <data
107               android:scheme="the scheme of your redirect url"
108               android:host="the host of your redirect url"
109               android:path="the path of your redirect url"
110               />
111       </intent-filter>
113   </activity>
115   ...

Authenticate With Firebase

Initiate the Snapchat OAuth 2.0 authorization process:

1import com.snapchat.kit.sdk.SnapLogin;
2import com.snapchat.kit.sdk.login.api.SnapLoginApi;
3import com.snapchat.kit.sdk.login.api.FirebaseCustomTokenResultCallback;
4import com.snapchat.kit.sdk.login.api.FirebaseCustomTokenResultError;
6.  .  .
8// Get the Login API
9SnapLoginApi loginApi = SnapLogin.getApi(this);
11// Trigger the Firebase Custom Token grant
12loginApi.startFirebaseTokenGrant(new FirebaseCustomTokenResultCallback() {
13     @Override
14     public void onSuccess(@NonNull String customToken) {
15         // Here you should be good to authenticate with Firebase
16         // using "signInWithCustomToken()" API
17     }
19     @Override
20     public void onFailure(@NonNull FirebaseCustomTokenResultError error) {
21         // Here you could update your UI to show the
22         // Firebase token grant failure
23     }
24 });

You can find more information on the signInWithCustomToken() API here.