Navigation

Quick start

This Quick Start guide will walk you through the steps to integrate Rupt into your Android app. By the end of this guide, you will have a fully working account sharing mechanism integrated on your application.

Step 1: Installation

  1. Ensure mavenCentral() and jitpack are added to your dependencyResolutionManagement block in your settings.gradle file. If it is not, add it like so:
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral()
            maven {
                url = URI("https://jitpack.io")
            }
        }
    }
  2. Add Rupt to your dependencies along with the required dependencies
    val navVersion = "2.7.7"
    implementation("dev.rupt.android:rupt-android:3.0.3")
    implementation("io.ktor:ktor-client-core:2.0.3")
    implementation("io.ktor:ktor-client-cio:2.0.3")
    implementation("io.ktor:ktor-client-content-negotiation:2.0.3")
    implementation("io.ktor:ktor-serialization-kotlinx-json:2.0.3")
    implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
    implementation("androidx.navigation:navigation-fragment-ktx:$navVersion")
    implementation("androidx.navigation:navigation-ui-ktx:$navVersion")
    implementation("androidx.navigation:navigation-compose:$navVersion")
    implementation("com.github.bumptech.glide:glide:4.16.0")
    implementation("com.github.appsfeature:otp-view:1.0")
    implementation("com.github.leandroborgesferreira:loading-button-android:2.3.0")
    implementation("com.squareup.okhttp3:okhttp:4.12.0")
    implementation("com.squareup.okhttp3:okhttp-sse:4.12.0")

Step 2: Usage

  1. Configure the SDK as soon as you have the user's account ID. This should be done as soon as the app launches or as soon as the user logs in.
    // REQUIRED
    Rupt.configure("<#client id#>", "account_id", email, phone, onCreateNewAccount, onLogoutCurrentDevice, onLimitExceeded)

    The parameters are:
    • client id*: Your Rupt client ID. You can find this on the Rupt dashboard.
    • account_id*: The account ID of the user. This is a unique identifier for the user.
    • email: The email of the user. This is optional. If you want to trigger 2FA when account sharing is detected, you should provide this.
    • phone: The phone number of the user. This is optional. If you want to trigger 2FA when account sharing is detected, you should provide this (if available).
    • onCreateNewAccount: A callback that is triggered when a user wants to create new account. See step 3 for more information.
    • onLogoutCurrentDevice: A callback that is triggered when the wants to logout of this device (or is kicked out by another remote device). See step 3 for more information.
    • onLimitExceeded: A callback that is triggered when the user has too many devices using their account. See step 3 for more information.
  2. Register the ChallengeActivity in your AndroidManifest.xml file.
    <activity
             android:name="dev.rupt.rupt.ui.ChallengeActivity"
             android:theme="@style/Theme.AppCompat.Light" />

    Notes:
    • The ChallengeActivity is the activity that will be shown to the user when account sharing is detected AND account sharing protection is enabled. It will never show if the setting is disabled.
    • The ChallengeActivity expects a theme that extends from Theme.AppCompat. If you have a custom theme, ensure it extends from Theme.AppCompat or you can just use @style/Theme.AppCompat.
  3. Attach the device to the user so that Rupt can start monitoring the user's account sharing.
    Rupt.attach(context) {
       Log.d("Rupt", "Attached. Device Id -> ${Rupt.deviceId}")
    }

    Ensure you call the attach when the app enters the foreground state as well. This will improve account sharing detection results.

    Calling attach multiple times will not create duplicate devices. It is perfectly safe.

Step 3: Handle callbacks

If Rupt determines that the user is sharing their account, and you have the Account sharing protection setting enabled, the user will see a challenge to verify they own this account, logout, or create a new account (i.e. stop sharing). Rupt will handle the verification, but you need to handle the logout and account creation.

Rupt.onCreateNewAccount = {
    //TODO: logout the current account and guide the user to create a new account
}
Rupt.onLogoutCurrentDevice = {
    //TODO: log the user out of this device
}

The callbacks can (and should) be passed as parameters to the Rupt.configure method. But you can also set them directly on the Rupt object and change them at any time, but it is recommended to set them as soon as the app launches. If you set them after the attach method, you may miss some events.