Freedom ID SDK Android

Introduction
Welcome to the Freedom ID SDK integration guide! This guide will help you smoothly integrate the Freedom ID SDK into your Android app, enabling secure authentication and user data permission management within the Freedom Holding ecosystem. Freedom ID serves as a single point of entry for users, ensuring top-level security and privacy while managing data permissions and accessing multiple services.
The Freedom ID SDK is available for both Android (API level 24 and above) and iOS platforms. This guide specifically covers the Android platform. Let's get started! 🚀
Getting Started
Prerequisites
Before you begin integrating the Freedom ID SDK into your Android app, ensure you have the following:
-An Android app project with a minimum API level of 24.
-An API key provided by Freedom Pay.
-The Freedom ID SDK AAR file provided by Freedom Pay
[!info] How to get API KEY and AAR?In order to get your API KEY and AAR you need to contact Freedom Pay providing the following data:
-ApplicationID
-Signing Fingerprint from your Google Play Account
Installation Instructions
Automatically
You can add the AAR via Project Structure's Dependency Tab as specified in the official docs here
.
Manually
Alternatively, you can use this method:
1.Place the freedom-id-sdk.aar in the libs directory of your app module. If the libs directory doesn’t exist, create it at the root of your app module (e.g., app/libs)
2.Add the AAR file as a dependency in the build.gradle file of your app module and settings.gradle
// build.gradle
dependencies {
    implementation files('libs/freedom-id-sdk.aar')
}
//settings.gradle
repositories {
flatDir {
             dirs("libs")
       }
}
3. Sync the project
Usage
Initialize the SDK
To initialize the Freedom ID SDK, call the create method of the FreedomID class. This method requires two parameters:
- The API key provided by Freedom ID.
- The application context.
val apiKey = YOUR_API_KEY
val context = applicationContext
val freedomID = FreedomID.create(apiKey, context)
Authorize a User
To authorize a user, call the authorize method of the FreedomID class. This method initiates the authorization flow. The authorize method takes three parameters:
  1. The FragmentManager of the activity or fragment where the authorization flow will be displayed.
  2. An array of DataGrants that the user needs to grant.
  3. A callback function that will be invoked when the authorization flow completes.
The authorization process returns an AuthResult object, which can be either:
  • Success: Contains a GrantedProfile object.
  • Error: Specifies the type of error that occurred.
Here's an example:
val fragmentManager = supportFragmentManager
val dataPermissions = arrayOf(DataGrants.READ_FIRSTNAME, DataPermissions.READ_LASTNAME)

freedomID.authorize(fragmentManager, dataPermissions) { authResult ->
    when(authResult) {
        is AuthResult.Success -> {
            // Authorization successful 🚀
            val profile = authResult.profile
            // Do something with the profile
        }
        is AuthResult.Error -> {
            // Authorization failed ⛔
            // Handle the error accordingly
        }
    }
}
Clear the SDK
To clear the SDK, call the clear method of the FreedomID class.
This method clears the SDK's internal state and releases any resources used during the authorization process.
freedomID.clear()
Authorization Flow
App Initialization
When the user opens the app, it automatically checks if there are any accounts tied to their device.

Account Check
- If an account exists: The user is navigated directly to the Home Screen, where their account(s) are displayed.
- If no account exists: The user is taken to the Screen to log in. After successful authentication, the user is redirected to the Home.

Authentication Screen Interaction
The user can log in using any of these methods:
- Entering their phone number and receiving an OTP code via SMS.
- Entering their email and password as credentials.
- Entering their phone number and password as credentials.
Optionally, users can enable 2FA for additional security. To enable 2FA, they need to manage their settings in their Freedom ID account on the web at https://passport.freedompay.kz

Home Screen Interaction
- On the Home screen, users see their account(s).
- Users select an account for which they need to request data permissions and apply fingerprint

Request for Permissions
- After selecting an account, the app presents the Permissions Request Screen.
- Users review the requested permissions (e.g., access to specific user data).

User Decision
- Permissions Granted ✅: The host app is granted the requested permissions.
- Permissions Denied ❌: The app returns to the Home Screen or informs the user that permissions are needed to proceed.

Completion
Once permissions are granted, the user is notified of successful authorization, and the SDK communicates the result back to the host app.
Data Structures


DataGrants Structure

General Description
This enum represents a set of permissions that a host application can request from the SDK to grant access to specific profile data.
Each constant corresponds to a particular piece of user information, allowing the host app to selectively request access based on its needs.
Below is a table describing the different DataGrants available in the Freedom ID SDK:
GrantedProfile Structure
General Description
The GrantedProfile data class represents a user's profile information that is accessible after the required read permissions have been granted by the host application via the SDK.
data class GrantedProfile(
    val id: String,
    val identifier: String,
    val email: String,
    val emails: List<String>,
    val nationality: String,
    val phone: String,
    val phones: List<String>,
    val dateOfBirth: String,
    val firstname: String,
    val lastname: String,
    val patronymic: String?,
    val gender: String,
    val country: String
)
AuthResult Structure
General Description
The AuthResult is a sealed interface representing the result of an authentication process. It has two primary branches:
  1. Success: Indicates a successful authentication with the granted user profile as its payload.
  2. Error: Represents various types of errors that may occur during the authentication process. Each error type is modeled either as :
a. A data object for static cases
b. Or a data class for cases requiring additional information.
Table1: AuthResult
Table 2: Error (Subtype of AuthResult)
TransmissionErrors Structure
General Description
The TransmissionErrors enum defines a set of possible errors that can occur during the transmission of requests in an authentication or communication process.
Each error represents a specific issue related to the request's structure, identification, application integrity, or the process of sending and receiving requests.
Table: TransmissionErrors
NetworkError Structure
General Description
The NetworkError sealed interface defines a set of possible errors that may occur during network operations.
Each subtype of NetworkError represents a specific issue, such as connection failures, stream interruptions, or problems with request/response handling.
Table: NetworkError
Support

If you have questions or need help integrating the SDK, feel free to reach out! 👋
Email: support@freedompay.kz