Skip to content

flida-dev/android-sdk

Repository files navigation

Flida Android SDK

The official Android SDK for integrating Flida authentication into your Android applications.

Installation

JitPack

  1. Add the JitPack repository to your settings.gradle (or root build.gradle):

    dependencyResolutionManagement {
        repositories {
            google()
            mavenCentral()
            maven { url 'https://jitpack.io' }
        }
    }
  2. Add the dependency to your app's build.gradle:

    dependencies {
        implementation 'com.github.flida-dev:android-sdk:Tag' // Replace 'Tag' with the latest version (e.g., 1.0.0)
    }

Configuration

1. Manifest Setup

You need to configure the redirect activity in your AndroidManifest.xml to handle the authentication callback. However, the SDK includes a FlidaRedirectActivity that is automatically merged. You just need to provide the flidaAuthHost placeholder in your build.gradle.

In your app's build.gradle:

android {
    defaultConfig {
        // ...
        manifestPlaceholders = [
            flidaAuthHost: "YOUR_CLIENT_ID.api.flida.dev" // Replace with your actual host
        ]
    }
}

2. Initialization

Initialize the SDK in your Application class or MainActivity.

import dev.flida.sdk.FlidaIDSDK

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // Initialize
        val sdk = FlidaIDSDK.initialize(this)
        
        // Configure
        sdk.configure(
            clientId = "YOUR_CLIENT_ID",
            scopes = listOf("openid", "name", "e-mail-address", "phone-number")
        )
    }
}

Usage

Authorize

To start the login flow:

FlidaIDSDK.shared.authorize(this) { result ->
    result.fold(
        onSuccess = { tokenResponse ->
            println("Access Token: ${tokenResponse.token.accessToken}")
        },
        onFailure = { error ->
            println("Error: ${error.message}")
        }
    )
}

Get User Info

Once authorized, you can fetch user details:

FlidaIDSDK.shared.getUserInfo { result ->
    result.fold(
        onSuccess = { user ->
            println("User Name: ${user.name}")
            println("User ID: ${user.id}")
        },
        onFailure = { error ->
            println("Error: ${error.message}")
        }
    )
}

Refresh Token

To refresh the access token:

FlidaIDSDK.shared.refreshToken { result ->
    // Handle result
}

Logout

To clear the session:

FlidaIDSDK.shared.logout()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages