# FusionAuth QuickStart for Android Java - AppAuth QuickStart integration of a Java-based Android app with FusionAuth. > For the index of this section of the site, see [llms.txt](https://4002.18-224-161-104.sslip.io/docs/llms.txt) ![Android Java - AppAuth](https://4002.18-224-161-104.sslip.io/img/icons/android.svg) In this QuickStart, you are going to build an Android app with Java and integrate it with FusionAuth. You'll be building it for [ChangeBank](https://www.youtube.com/watch?v=CXDxNCzUspM), a global leader in converting dollars into coins. It'll have areas reserved for users who have logged in as well as public facing sections. The Docker Compose file and source code for a complete application are available at [https://github.com/FusionAuth/fusionauth-quickstart-java-android-native](https://github.com/FusionAuth/fusionauth-quickstart-java-android-native). ## Prerequisites * [Android Studio](https://developer.android.com/studio): The official IDE for Android will help you develop and install necessary tools to set it up. * There, you need to [install at least JDK 17](https://developer.android.com/build/jdks). * [Git](https://git-scm.com/site): You'll use it to clone the base repository. * [Docker](https://www.docker.com): The quickest way to stand up FusionAuth. (There are [other ways](https://4002.18-224-161-104.sslip.io/docs/get-started/download-and-install.md)). This app was built on top of [AppAuth](https://github.com/openid/AppAuth-Android), which is an open source client SDK for communicating with OAuth 2.0 and OpenID Connect providers. AppAuth supports Android API 16 (Jellybean) and above. ## General Architecture Here's a typical application login flow before FusionAuth: ```mermaid sequenceDiagram participant User participant App as Application User ->> App : View Homepage User ->> App : Click Login Link App ->> User : Show Login Form User ->> App : Fill Out and Submit Login Form App ->> App : Authenticates User App ->> User : Display User's Account or Other Info ``` Request flow during login before FusionAuth And here's the same application login flow after introducing FusionAuth: ```mermaid sequenceDiagram participant User participant App as Application participant FusionAuth User ->> App : View Homepage User ->> App : Click Login Link (to FusionAuth) User ->> FusionAuth : View Login Form FusionAuth ->> User : Show Login Form User ->> FusionAuth : Fill Out and Submit Login Form FusionAuth ->> FusionAuth : Authenticates User FusionAuth ->> User: Go to Redirect URI User ->> App: Request the Redirect URI App ->> FusionAuth : Is User Authenticated? FusionAuth ->> App : User is Authenticated App ->> User : Display User's Account or Other Info ``` Request flow during login after FusionAuth In general, you are introducing FusionAuth in order to normalize and consolidate user data. This helps make sure it is consistent and up-to-date as well as offloading your login security and functionality to FusionAuth. ## Getting Started In this section, you'll get FusionAuth up and running and use `git` to create a new application. ### Clone the Code First off, grab the code from the repository and navigate into that directory: ```shell-session $ git clone https://github.com/FusionAuth/fusionauth-quickstart-java-android-native.git ``` ```shell-session $ cd fusionauth-quickstart-java-android-native ``` ### Run FusionAuth via Docker You'll find a Docker Compose file (`docker-compose.yml`) and an environment variables configuration file (`.env`) in the root directory of the repo. Assuming you have Docker installed, you can stand up FusionAuth on your machine with the following. ```shell-session $ docker compose up -d ``` Here you are using a bootstrapping feature of FusionAuth called [Kickstart](https://4002.18-224-161-104.sslip.io/docs/get-started/download-and-install/development/kickstart.md). When FusionAuth comes up for the first time, it will look at the `kickstart/kickstart.json` file and configure FusionAuth to your specified state. Note If you ever want to reset the FusionAuth application, you need to delete the volumes created by Docker Compose by executing `docker compose down -v`, then re-run `docker compose up -d`. FusionAuth will be initially configured with these settings: * Your client Id is `e9fdb985-9173-4e01-9d73-ac2d60d1dc8e`. * Your client secret is `super-secret-secret-that-should-be-regenerated-for-production`. * Your example username is `richard@example.com` and the password is `password`. * Your admin username is `admin@example.com` and the password is `password`. * The base URL of FusionAuth is `http://localhost:9011/`. You can log in to the [FusionAuth admin UI](http://localhost:9011/admin) and look around if you want to, but with Docker and Kickstart, everything will already be configured correctly. Note If you want to see where the FusionAuth values came from, they can be found in the [FusionAuth app](http://localhost:9011/admin). The tenant Id is found on the Tenants page. To see the Client Id and Client Secret, go to the Applications page and click the `View` icon under the actions for the ChangeBank application. You'll find the Client Id and Client Secret values in the `OAuth configuration` section. Caution The `.env` file contains passwords. In a real application, always add this file to your `.gitignore` file and never commit secrets to version control. ### Set Up A Public URL For FusionAuth Your FusionAuth instance is now running on a different machine (your computer) than the mobile app will run (either a real device or an emulator), which means that it won't be able to access `localhost`. If the device and your computer are not connected to the same network or if you have something that blocks connections (like a firewall), learn [how to expose a local FusionAuth instance to the internet](https://4002.18-224-161-104.sslip.io/docs/get-started/download-and-install/development/exposing-instance.md). In summary, the process entails configuring [ngrok](https://ngrok.com/download) on your local system, [starting your FusionAuth instance on port 9011](#run-fusionauth-via-docker), and subsequently executing the following command. ```shell ngrok http --request-header-add 'X-Forwarded-Port:443' 9011 ``` This will generate a public URL that you can use to access FusionAuth when developing the app. If the device (either real or emulator) and your computer are connected to the same network, you can use the local IP Address for your machine (for example, `192.168.15.2`). Here are a few articles to help you find your IP address, depending on the operating system you are running: * [Linux](https://linuxize.com/post/how-to-find-ip-address-linux/#find-your-public-ip-address) * [Mac](https://support.apple.com/guide/mac-help/find-your-computers-name-and-network-address-mchlp1177/mac) * [Windows](https://support.microsoft.com/en-us/windows/find-your-ip-address-in-windows-f21a9bbc-c582-55cd-35e0-73431160a1b9) ### Configure FusionAuth Instance Now that you have [exposed your instance](#set-up-a-public-url-for-fusionauth), you need to update the Tenant issuer to make sure it matches the given address. Log into the [FusionAuth admin UI](http://localhost:9011/admin), browse to `Tenants` in the sidebar, click edit on the **Default** tenant to edit it. Paste the complete address *(with protocol and domain)* you copied from ngrok into the **Issuer** field (e.g. `https://6d1e-2804-431-c7c9-739-4703-98a7-4b81-5ba6.ngrok-free.app`). Save the application by clicking the save icon in the top right corner. Navigate to Applications and click edit on the **Example Android App** application. Click on the JWT tab, change both `Access token signing key` and `Id token signing key` to `Auto generate a new key on save...` and save the application. Note You must create new keys after modifying the `Tenant` because the **Issuer** field is embedded in the key. ### Create your Android App Now you are going to create an Android app. While this section builds a simple Android app on top of the [AppAuth demo app](https://github.com/openid/AppAuth-Android), you can use the same configuration to integrate your existing app with FusionAuth. ```shell-session $ git clone https://github.com/FusionAuth/openid-AppAuth-Android.git && \ cd openid-AppAuth-Android ``` Start by removing some unused files: ```shell-session $ rm app/java/io/fusionauth/app/BrowserSelectionAdapter.java && \ rm app/res/layout/browser_selector_layout.xml ``` Change the package namespace in `app/build.gradle`. You can replace the entire file with below contents. ```groovy apply plugin: 'com.android.application' apply plugin: 'checkstyle' apply from: '../config/android-common.gradle' apply from: '../config/keystore.gradle' android { namespace 'io.fusionauth.app' defaultConfig { applicationId 'io.fusionauth.app' project.archivesBaseName = 'fusionauth-demoapp' vectorDrawables.useSupportLibrary = true // Make sure this is consistent with the redirect URI used in res/raw/auth_config.json, // or specify additional redirect URIs in AndroidManifest.xml manifestPlaceholders = [ 'appAuthRedirectScheme': 'io.fusionauth.app' ] } signingConfigs { debugAndRelease { storeFile file("${rootDir}/appauth.keystore") storePassword "appauth" keyAlias "appauth" keyPassword "appauth" } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } lintOptions { lintConfig = file("${projectDir}/lint.xml") } buildTypes { debug { signingConfig signingConfigs.debugAndRelease } release { signingConfig signingConfigs.debugAndRelease } } } dependencies { implementation "net.openid:appauth:0.11.1" implementation "androidx.appcompat:appcompat:${project.androidXVersions.appcompat}" implementation "androidx.annotation:annotation:${project.androidXVersions.annotation}" implementation "com.google.android.material:material:${project.googleVersions.material}" implementation "com.github.bumptech.glide:glide:${project.googleVersions.glide}" implementation "com.squareup.okio:okio:${project.okioVersion}" implementation "joda-time:joda-time:${project.jodaVersion}" annotationProcessor "com.github.bumptech.glide:compiler:${project.googleVersions.glide}" } apply from: '../config/style.gradle' ``` Replace `app/AndroidManifest.xml` as well. ```xml ``` ## Authentication We'll use the [AppAuth Library](https://github.com/openid/AppAuth-Android), which simplifies integrating with FusionAuth and creating a secure web application. ### Configure AppAuth Modify `app/res/raw/auth_config.json` to use the values provisioned by Kickstart. Update the `discovery_uri` value; change `https://[YOUR-NGROK-MAIN-DOMAIN]` to the URL you wrote when [exposing your instance](#set-up-a-public-url-for-fusionauth). ```json { "client_id": "e9fdb985-9173-4e01-9d73-ac2d60d1dc8e", "redirect_uri": "io.fusionauth.app:/oauth2redirect", "end_session_redirect_uri": "io.fusionauth.app:/oauth2redirect", "authorization_scope": "openid email profile offline_access", "discovery_uri": "https://[YOUR-NGROK-MAIN-DOMAIN]/.well-known/openid-configuration/d7d09513-a3f5-401c-9685-34ab6c552453", "https_required": true } ``` ### Change Activities An [Activity](https://developer.android.com/guide/components/activities/intro-activities) is a screen for your app, combining the User Interface as well as the logic to handle it. Start by changing the login activity layout at `app/res/layout/activity_login.xml`. Replace it with the below XML. ```xml