Minimum supported Android version: 24
The BirID Android SDK facilitates authorization through the BirID authorization code. It handles the process of opening the Birbank application, verifying users within the Birbank application, and obtaining the authorization code, which can be exchanged for an authorization token.
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'
}
}
}All interactions are handled through the BirIDManager class. You need to create an instance (this can vary based on your approach and architecture, but it must be maintained until the flow is completed).
1. Add the BirIdButton to the layout.
<az.kapitalbank.birid_sdk.auth.BirIdButton
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />2. Build the BirIDManager object using its Builder class by providing the mandatory fields:
val loginBtn = findViewById<Button>(R.id.btnLogin)
loginBtn.setOnClickListener {
birIDManager = BirIDManager.Builder(clientId, state, codeChallenge, redirectUri, loaderIcon).build()
}Here are all the fields that can be provided:
BirIDManager
.Builder(clientId, state, codeChallenge, redirectUri, loaderIcon)
.loginHint("994000000000")
.codeChallengeMethod("S256")
.scope("openid email profile")
.responseType("code")
.locale(BirIdLocale.RU)
.nonce("nonce")
.environment(SsoEnvironment.PROD)
.appInstanceId(your_firebase_app_instance_id)
.build()codeChallengeMethod, scope, and responseType, their default values will be used, as shown in the code block above.locale parameter. There are 3 options for selecting locale: BirIdLocale.AZ, BirIdLocale.RU, and BirIdLocale.EN. The default value (if not provided) is AZ.environment parameter. There are 3 options for selecting environment: SsoEnvironment.PRE, SsoEnvironment.TEST, SsoEnvironment.DMZ and SsoEnvironment.PROD. The default value (if not provided) is PROD.appInstanceId if you want to track events related to your app. If not provided, custom id will be generated and you may not be able to keep track of your flow if you want to log events.The loader icon, which is the logo of the client application, will be displayed in the loader dialog before opening BirBank or the webview. It must be provided as a drawable.
3. Call the loginWithBirID method of the BirIDManager object that you created, passing the context. The context is required to launch the Birbank application's intents and to open WebViewActivity in case Birbank is not installed on the device. If showOnlyWebFlow parameter is not set value, it will follow the regular flow logic, but when client wants to continue with only app2web flow, it should pass the showOnlyWebFlow parameter with value of "true".
loginBtn.setOnClickListener {
birIDManager = BirIDManager
.Builder(clientId, state, codeChallenge, redirectUri, loaderIcon)
.loginHint("511234567")
.codeChallengeMethod("S256")
.scope("openid email profile")
.responseType("code")
.build()
birIDManager?.loginWithBirID(activity = this, showOnlyWebFlow = false)
}4. After the first two steps, the flow will be initiated. Following authorization via Birbank, a deeplink containing the BirIdResultModel will be sent in the reverse intent. To capture the results of the authorization code flow, override onNewIntent() and call the getBirIdResult() method, passing the intent and context.
In the manifest of your application, specify the scheme and host of the reverse deeplink for the activity that will process the result of authorization using BirID. These must match the redirectUri registered in IdP and the one sent to us.
If you want to process the reverse deeplink in the same activity where authentication started, specify singleTop in the launchMode attribute for your activity and receive the intent with the result in the "onNewIntent(intent: Intent)" method.
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (intent.extras != null) {
val birIdResult = birIDManager?.getBirIdResult(this, intent)
birIdResult?.let {
// continue your app's flow after getting the result
}
}
}Calling the getBirIdResult method is also essential for handling the opening of WebView if no user is logged into Birbank.
This is the BirIdResultModel:
data class BirIdResultModel(
val code: String?,
val sessionState: String?,
val state: String?,
val errorDescription: String?
)<activity
android:name=".LoginActivity"
android:launchMode="singleTop"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="sso_test"
android:scheme="app" />
</intent-filter>
</activity>The SDK will check the scope you send against the scope received from the authorization token service. If they differ, you will receive an error description in the BirIdResultModel. In this case, the error description will be "scopes_do_not_match".