This example application demonstrates how one may use Stytch within an Android application, using Jetpack Compose.
This project uses Stytch's Android SDK which provides headless methods to securely interact with Stytch.
This application features SMS OTP as well as Apple and Google OAuth authentication. You can use this application's source code as a learning resource, or use it as a jumping off point for your own project. We are excited to see what you build with Stytch!
Follow the steps below to get this application fully functional and running using your own Stytch credentials.
-
Create a Stytch account. Once your account is set up a Project called "My first project" will be automatically created for you.
-
Within your new Project, navigate to SDK configuration, and make the following changes:
-
Navigate to Redirect URLs, and add
stytch-example://oauth
as type Login and Sign-up. -
Navigate to OAuth, and set up login for Apple and Google in the Test environment. Follow all the instructions provided in the Dashboard. If you are not interested in OAuth login you can skip this step. However, the Continue with Apple and Continue with Google buttons in this application will not work. NOTE: for this example app's Apple OAuth config, only Team ID and Application ID fields require real data, the other fields can be stubbed out with fake data.
-
Finally, navigate to API Keys, and copy your
public_token
. You will need this value later on.
In your terminal clone the repo and open the Android Studio project:
git clone https://github.com/stytchauth/stytch-android-example.git
Next, add your STYTCH_PUBLIC_TOKEN
and GOOGLE_OAUTH_CLIENT_ID
in local.properties
. In a production scenario, you might fetch this token from your backend, or configure as an env var in your CI/build pipeline.
After completing all the set up steps above the application can be run as normally from Android Studio.
You'll be able to login with SMS OTP, Sign In With Apple, or Google OAuth and see your values from your Stytch User object as well as see how logging out works.
This example app showcases a small portion of what you can accomplish with Stytch. Here are a few ideas to explore:
- Add additional login methods like Passwords or Biometrics.
- Take advantage of the SDK's headless methods and replace the included UI with your own look and feel.
- Use Stytch Sessions to secure your backend.
Join the discussion, ask questions, and suggest new features in our Slack community!
Check out the Stytch Forum or email us at support@stytch.com.