React Native SDK
SDKs and APIs
The Kinde React Native SDK allows developers to quickly and securely integrate a new or an existing React Native application into the Kinde platform. This SDK is for people using Expo.
We support Expo with React Native versions 0.70 and higher.
Use this document for Expo and React Native.
To use just React Native, see React Native SDK. You can also view the React Native docs and React Native starter kit in GitHub.
We are working on creating an updated Expo package (it is being tested) and we will add a link here when it’s ready.
If you haven’t already got a Kinde account, register for free here (no credit card required). Registering gives you a Kinde domain, which you need to get started, e.g. yourapp.kinde.com
.
You will need Node, the React Native command line interface, a JDK, Android Studio (for Android) and Xcode (for iOS).
Follow the installation instructions for your chosen OS to install dependencies.
The SDK can be installed using your package manager or expo
cli
Configure the deep link support for your app
Edit android/settings.gradle
Edit android/app/build.gradle
Edit MainApplication.java
In React Native version 0.73 or above, the MainApplication.java
file has been replaced with MainApplication.kt
Execute the command yarn run android
or npx expo run:android
Install the CocoaPods. We recommend installing CocoaPods using Homebrew.
Install the SDK
Add the following to your Podfile
and run pod update:
Execute the command yarn run ios
or npx expo run:ios
If you encounter any errors during the SDK installation process, you can refer to the General tips section at the bottom of this document, for troubleshooting guidance.
<myapp://localhost:3000>/kinde_callback
<myapp://localhost:3000>/kinde_callback
Make sure you press the Save button at the bottom of the page!
Note: The <myapp://localhost:3000>/kinde_callback/kinde_callback
is used as an example of local URL Scheme, change to the local URL Scheme or production URL Scheme that you use.
If you would like to use our Environments feature as part of your development process. You will need to create them first within your Kinde account. In this case you would use the Environment subdomain in the code block above.
Put these variables in your .env file. You can find these variables on the same page as where you set the callback URLs.
KINDE_ISSUER_URL
- your Kinde domainKINDE_POST_CALLBACK_URL
- After the user authenticates we will callback to this address. Make sure this URL is under your allowed callback URLsKINDE_POST_LOGOUT_REDIRECT_URL
- where you want users to be redirected to after logging out. Make sure this URL is under your allowed logout redirect URLsKINDE_CLIENT_ID
- you can find this on the App Keys pageNote: The myapp://localhost:3000/kinde_callback
is used as an example of local URL Scheme, change to the local URL Scheme or production URL Scheme that you use.
To link to your development build or standalone app, you need to specify a custom URL scheme for your app. You can register a scheme in your Expo config (app.json, app.config.js) by adding a string under the scheme
key:
Expo Go uses the exp://
scheme, however, if we link to exp://
without any address afterward, it will open the app to the home screen.
In development, your app will live at a url like exp://127.0.0.1:19000
. When published, an experience will be hosted at a URL like exp://u.expo.dev/[project-id]?channel-name=channel-name]&runtime-version=[runtime-version]
, where u.expo.dev/[project-id]
is the hosted URL that Expo Go fetches from.
Caution: You also should update your callback URL to both your app and Kinde.
To create a new instance of the KindeSDK object, execute the code below.
Kinde provides methods for easily implementing a login / register flow.
As an example if you add buttons as follows.
Then define new functions that match for each button.
Note: Make sure you’ve already defined KindeSDK as client in the state.
This is implemented in much the same way as signing in or registering. The Kinde SPA client comes with a logout method:
We have also implemented an API for token revocation. Pass true
as an argument in the logout
function. This flag will assist in revoking the token without having to open the website within your apps.
Note: Handle redirects are now deprecated
Starting from version 1.1 of the SDK, the need to handle redirects has been eliminated. Authentication is now performed by launching a web browser within your app instead of relying on an external browser. For a comprehensive example of how to handle authentication, see below.
To access the user information, use the getUserDetails
helper function.
Go to the Users page within Kinde to see your newly registered user.
Once a user has been verified, your product/application will return the JWT token with an array of permissions for that user. You will need to configure your product/application to read permissions and unlock the respective functions.
Set permissions in your Kinde account. Here’s an example set of permissions.
We provide helper functions to more easily access permissions.
A practical example in code might look something like.
An audience is the intended recipient of an access token - for example the API for your application. The audience argument can be passed to the Kinde client to request an audience be added to the token.
The audience of a token is the intended recipient of the token.
For details on how to connect, see Register an API.
By default the KindeSDK
requests the following scopes:
You can override this by passing scope into the KindeSDK
We have provided a helper to grab any claim from your id or access tokens. The helper defaults to access tokens:
For information about how organizations work in Kinde, see Kinde organizations for developers.
To create a new organization within your application, you will need to run a similar function to this.
Then define the function of the button.
Make sure you’ve already defined KindeSDK
as the client in the state.
Kinde has a unique code for every organization. You’ll have to pass this code through when you register a new user.
Example function below:
If you want a user to sign in into a particular organization, pass this code along with the sign in method.
Following authentication, Kinde provides a json web token (jwt) to your application. Along with the standard information we also include the org_code
and the permissions for that organization (this is important as a user can belong to multiple organizations and have different permissions for each). Example of a returned token:
Example of a returned token:
The id_token
will also contain an array of organizations that a user belongs to - this is useful if you wanted to build out an organization switcher for example.
There are two helper functions you can use to extract information.
Once the user has successfully authenticated, you’ll have a JWT and a refresh token and that has been stored securely. E.g. using the getAccessToken
method of the Storage
class to get an access token.
We’re using the expo-secure-store for Expo
.
The storage handler can be found at: Storage class
Run the test suite using the following command at the root of your React Native.
Note: Ensure you have already run npm install
issuer
Either your Kinde URL or your custom domain. e.g https://yourapp.kinde.com
.
Type: string
Required: Yes
redirectUri
The URL that the user will be returned to after authentication.
Type: string
Required: Yes
clientId
The unique ID of your application in Kinde.
Type: string
Required: Yes
logoutRedirectUri
Where your user will be redirected when they sign out.
Type: string
Required: No
scope
The scopes to be requested from Kinde.
Type: boolean
Required: No
Default: openid profile email offline
additionalParameters
Additional parameters that will be passed in the authorization request.
Type: object
Required: No
Default: {}
additionalParameters - audience
The audience claim for the JWT.
Type: string
Required: No
login
Constructs a redirect URL and sends the user to Kinde to sign in.
Arguments:
Usage:
Allow org_code
to be provided if a specific organization is being signed into.
Sample output:
register
Constructs a redirect URL and sends the user to Kinde to sign up.
Arguments:
Usage:
Allow org_code
to be provided if a specific organization is being registered to.
Sample output:
logout
Logs the user out of Kinde.
Arguments:
Usage:
Sample output: true
or false
getToken
Returns the raw Access token from URL after logged from Kinde.
Arguments:
Usage:
You need to have already authenticated. Otherwise, an error will occur.
Sample output:
createOrg
Constructs a redirect URL and sends the user to Kinde to sign up and create a new organization in your business.
Arguments:
Usage:
Allow org_name
to be provided if you want a specific organization name when you create.
Sample output:
getClaim
Gets a claim from an access or ID token.
Arguments:
Usage:
Sample output:
getPermission
Returns the state of a given permission.
Arguments: key: string
Usage:
Sample output:
getPermissions
Returns all permissions for the current user for the organization they are signed into.
Usage:
Sample output:
getOrganization
Get details for the organization your user is signed into.
Usage:
Sample output:
getUserDetails
Returns the profile for the current user.
Usage:
Sample output:
getUserOrganizations
Gets an array of all organizations the user has access to.
Usage:
Sample output:
isAuthenticated
Return the boolean to demonstrate whether the user is authenticated or not.
Usage:
Sample output: true
or false
'value'
is unavailable: introduced in iOS 12.0
If you got the error ‘value’ is unavailable: introduced in iOS 12.0 when trying to build the app, you can follow the below steps to fix that:
Dependency 'androidx.browser:browser:1.6.0-beta01'
requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs.
The solution is add androidXBrowser = "1.4.0"
in your project.
Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.10 (org.jetbrains.kotlin:kotlin-stdlib:1.8.10) and jetified-kotlin-stdlib-jdk8-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.22)
The solution is add org.jetbrains.kotlin:kotlin-bom:1.8.0
dependency in your project.
Sometimes there will be issues related to caching when you develop React Native. There are some recommendations for cleaning the cache:
node_modules
, yarn.lock
or package-lock.json
.yarn cache clean
or npm cache clean --force
..env
file.yarn install
or npm install
.yarn start --reset-cache
or npm start --reset-cache
.Assume your StarterKit path is <StarterKit_PATH>
.
Clean cache for Android
Run this:
Clean cache for iOS
Run this:
Clean build folders on Xcode.
If you need help connecting to Kinde, please contact us at support@kinde.com.