The official Android SDK for integrating Flida authentication into your Android applications.
-
Add the JitPack repository to your
settings.gradle(or rootbuild.gradle):dependencyResolutionManagement { repositories { google() mavenCentral() maven { url 'https://jitpack.io' } } } -
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) }
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
]
}
}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")
)
}
}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}")
}
)
}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}")
}
)
}To refresh the access token:
FlidaIDSDK.shared.refreshToken { result ->
// Handle result
}To clear the session:
FlidaIDSDK.shared.logout()