The latest source code of the Keyri Android SDK can be found here: https://github.com/Keyri-Co/keyri-android-whitelabel-sdk/releases
Supply these three parameters to your app: - app key - public Key - callback URL
For example (using module build.gradle file):
And then use them to initialize the SDK object:
Or provide it with Koin DI:
Please note that allowMultipleAccounts flag is needed in order to determine the behavior of the SDK when registering a new user when there is already an existing one in the system. true - a new account will be created in the database upon registration, regardless of whether there are other accounts registered in the database. false - when registering a new account, when there is already one in the database, an exception MultipleAccountsNotAllowedException will be thrown.
To handle deeplinks (e.g., for QR login straight from the user's built-in camera app) you need to define in your AndroidManifest.xml following intent-filter block:
This will handle all links with such scheme: https://www.keyri.com/application?sessionId=324e23.
In the activity where the processing of links is declared, you need to add handlers in the onNewIntent() and onCreate() methods:
The last thing you need to do in order for your deep links to be processed is to create the associations for each of the declared hosts for handling in JSON file as described here: https://developer.android.com/training/app-links/verify-site-associations.
Add KeyriScannerView in your layout:
Alternatively, if you want to provide a custom authentication/authorization UI/UX, use the following methods:
To manage accounts use the following methods:
To use Keyri SDK with an existing authorization system, there is no need to remove the old one. You can easily integrate Keyri SDK into your system. To do this, first, add the SDK dependency to your project as shown in the Integration section.
To adapt an existing account to the SDK, you need to check if the account exists in the SDK local storage. Call the accounts() method, which will return a list of PublicAccount objects. Look up your account by unique user ID or any other unique ID equal to custom field of PublicAccount object.
Call the mobileSignup() method if no account is found, passing the username and the user's unique ID or any other unique ID as the custom argument. After that, the user will be created and the method will return the AuthMobileResponse, which contains User entity, Auth Token and Refresh Token as shown below:
If the needed PublicAccount is present in the SDK storage, call the mobileLogin() method, passing this account to it. You will be returned the user entity, token, and refresh token as in mobileSignup(). AuthMobileResponse will be returned, so you need to encrypt and save Auth Token and Refresh Token and use them as you did before (Bearer token, etc.).
Logout and account deletion
When you want to log out user from the system, remove the account from the Keyri SDK by calling removeAccount() method and passing in the PublicAccount.