19min

React Native

The latest source code of the Keyri iOS SDK can be found here: https://github.com/Keyri-Co/react-native-keyri

Integration

The Keyri React Native SDK can be integrated using yarn or npm.

Ruby
|

Subsequently, install dependencies for iOS. Android should automatically link all dependencies, but iOS requires you to install CocoaPods dependencies. After running one of the above commands, navigate to the ios directory and run this command:

Ruby
|

And that's it! You can use the Keyri SDK inside your project.

Provisioning Keyri Config Parameters

Supply these three parameters to your app from the Keyri dashboard: - appkey - rpPublicKey - callbackUrl

And then use them to configure the SDK before initialization:

JS
|

You need to set up universal links according to the iOS and Android documentation. After this is set up, follow this guide to handle deep links in your React Native app: (link).

This will handle all links with such schemes: https://{domainName}/application?sessionId=324e23.

After handlers for deep links are added, you can use it as in the example below:

JS
|

Option 1: Use the built-in QR authentication UI/UX

Use the built-in QR authentication interface, which handles signup and login operations under the hood

JS
|

Option 2: Build a custom authentication/authorization UI/UX

Alternatively, if you want to provide a custom authentication/authorization UI/UX, use the following methods:

  • onReadSessionId()- call it after retrieving the sessionId from QR-code or deep link.
  • signup() - Must be called after onReadSessionId(). This method is needed to create a user for the Desktop agent (i.e. if the user does not already have an account and is trying to register). Pass username, sessionId, service, and any custom param needed to work with your identity management system.
  • login() - this method is needed to log in user for Desktop agent. Must be called after onReadSessionId(). Pass public account identifies (e.g., username), sessionId, service, and custom param.
JS
|
  • mobileSignup() - method to create user on mobile device.
JS
|
  • mobileLogin() - method to login user on mobile device.
JS
|

Manage Accounts

  • accounts() - retrieve all public accounts from storage.
  • removeAccount() - remove public account from storage
JS
|

Integration into an existing system

To use the Keyri SDK with an existing authorization system, there is no need to remove the old one. You can easily integrate the Keyri SDK into your system. To do this, first, add the SDK dependency to your project as shown in the Integration section.

Registration

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:

JSON
|

Login

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.



Updated 09 Feb 2022
Did this page help?
Yes
No