Logo

BirID Profile

BirID Profile provides detailed and unified source of information for users to see their displayed data. By using this component, users will be able to manage their profile across applications linked to BirID.

Latest SDK version → 1.2.7

Connection - maven

Add the following dependency to the module-level build.gradle file.

implementation("az.kapitalbank.birid:BirIDSDK:1.2.7@aar") { //check the latest version
    transitive = true
}

If you have Glide dependency being used in your project and it causes conflicts while building, use this version to properly build your project

implementation("az.kapitalbank.birid:BirIDSDK:1.2.7@aar") { //check the latest version
    exclude group: 'com.github.bumptech.glide', module: 'glide'
    exclude group :'com.github.bumptech.glide', module: 'compiler'
    transitive = true
}

Add the following lines to the project-level build.gradle file.

allprojects {
    maven {
        url "REGISTRY_URL"
        credentials {
            username = 'CLIENT_USERNAME'
            password = 'CLIENT_PASSWORD'
        }
    }
}

Setting up BirID Profile

BirIdProfileManager class is responsible for setting up and displaying user's data as a field in your application. BirIdProfileManager accepts following parameters that should be defined and provided by client side:

1. First of all, we should add BirIdProfileCard component to the layout:

<az.kapitalbank.birid_sdk.profile.ui.component.BirIdProfileCard
    android:id="@+id/profileCard"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

2. Next step is creating a class instance and implementing BirIdTokenProvider instance provided by SDK. After that you should pass an instance of it to BirIdProfileManager element ( shown in 3rd step). Recommended retrieval logic shown below:

class BirIdTokenProviderImpl: BirIdTokenProvider {
    override suspend fun refreshBirIdToken(): Result<String> {
        return try {
            // token retrieval logic
            Result.success(your_token)
        } catch(e: Throwable) {
            // error handling logic
            Result.failure(e)
        }
    }
}

3. Then you can provide this component in your code and pass it to Builder as a parameter: (Token should be provided as a plain format, not as a "Bearer $token" format) Also, context should be provided for the context field. It might be requireContext() if you use fragments, or this@YourActivity if it is activity

val birIdProfileCard = findViewById<BirIdProfileCard>(R.id.profileCard)

val profileManager = BirIdProfileManager.Builder(
   context = this@YourActivity, 
   birIdProfileCard = birIdProfileCard, 
   accessToken = TOKEN,
   birIdTokenProviderInstance = BirIdTokenProviderImpl(),
   environment = SsoEnvironment.PROD,
).build()

Parameters

  • context: Android Context which will help Profile component to continue its lifecycle through the same context with your container.
  • birIdProfileCard: The component reference for BirIdProfileCard.
  • token: User's access token for BirID.
  • birIdTokenProviderInstance: It is the instance of the component that implements the BirIdTokenProvider interface provided by SDK for token refresh logic. You should implement your refreshToken retrieval logic inside it.
  • environment: it is an optional field that has SsoEnvironment.PROD by default. It determines the environment SDK uses.

4. To load data using the profileManager, use loadProfileData() method. While onError is mandatory field to handle, it is optional to handle onFlowFinished field:

profileManager.loadProfileData(
    onError = { error ->
        when(error) {
            BirIdProfileException.SERVICE_NOT_AVAILABLE -> TODO()
            BirIdProfileException.IMAGE_LOAD_FAILED -> TODO()
            BirIdProfileException.UNABLE_TO_RETRIEVE_TOKEN -> TODO()	
        }
    },
    onFlowFinished = { result ->
        when(result) {
            FlowFinishedResult.USER_INFO_UPDATED -> TODO()
        }
    }
)

Error Types

  • SERVICE_NOT_AVAILABLE: This error is returned when service on BirIdProfile side fails to fetch data or somehow there is a possible error.
  • UNABLE_TO_RETRIEVE_TOKEN: When profile data is being loaded, SDK checks accessToken provided to itself, if it is expired, it tries to retrieve refreshed token via the instance implemented by BirIdTokenProvider and if the result is failure, it throws this error.
  • IMAGE_LOAD_FAILED: This error is returned when there is an error related to profile photo.

Result Types

  • USER_INFO_UPDATED: This result type is returned when user's data is updated while being present in the app, if there is any update, you will receive USER_INFO_UPDATED enum and you might update your cache, or call you update services.