Passkey Authentication
Passkeys in React Native provide secure authentication for both primary authentication (1FA) and multi-factor authentication (2FA), allowing users to use passkeys as their primary login method or as a second factor to enhance account security.
To use passkeys in your React Native app, your website domain must grant credential access to the mobile app so passkeys can be created associated with the website domain. This allows users to seamlessly use the same passkeys across both your app and website.
Prerequisites
Before setting up passkeys, ensure you have:
- A React Native project with Dynamic SDK already integrated
- A domain/website that you control (for hosting the required
.well-known
endpoints) - Access to your appโs bundle identifier and signing certificates
- For iOS: Apple Developer account and Xcode
- For Android: Android Studio and signing key information
Installation
Install the required package using your preferred package manager:
Post-Installation Steps
After installing the react-native-passkey
package, you need to link the native packages to your project:
For iOS
For Expo Projects
If you are using Expo, you may need to run a prebuild or create a new build:
Or use the EAS service to create a new build for your app:
After running expo prebuild
, youโll need to rebuild your app for the native modules to be properly linked.
Configuration
Dynamic SDK Configuration
To create passkeys associated with the correct website, you must configure the appOrigin
in the ReactNativeExtension:
The appOrigin
must match your website domain exactly (e.g., https://example.com
). This domain will be used to create and associate passkeys, so ensure itโs the same domain where youโll host the required .well-known
endpoints.
OS Configuration
iOS
There are iOS-specific steps to configure Passkey support. If you have already set up an associated domain for your application, you can skip this step.
Set Up an Associated Domain for Your Application
Follow the Apple documentation to associate a domain with your application. On your webserver, set up this route:
This route should serve a static JSON object containing your team ID and bundle identifier. Example (replace XXXXXXXXXX with your team identifier and โYYY.YYYYY.YYYYYYYYYYYYYYโ with your bundle ID, e.g., H123456789.com.example.mobileApp):
In Xcode, under Signing & Capabilities, add a new Capability of type Associated Domains. Now add this and replace XXXXXX with your domain (e.g., apple.com):
If you are using Expo, add the webcredentials:{{yourdomain}} to your app.json file. See the Expo documentation for more details.
You can validate your Apple App Site Association (AASA) configuration using the Branch AASA Validator. This tool tests your domain against Appleโs requirements and helps ensure your Universal Links and passkey setup is properly configured.
Android
The Android-specific configuration is similar to iOS. If you have already set up Digital Asset Links for your application, you can skip this step.
Associate Your App with a Domain
Follow the Android documentation to associate a domain with your application. On your webserver, set up this route:
This route should serve a static JSON object containing the following information (replace with your data, and replace SHA_HEX_VALUE with the SHA256 fingerprints of your Android signing certificate):
Managing passkeys
Now that your application has correctly associated your domain with your application, you can register and authenticate using passkeys for both primary authentication (1FA) and multi-factor authentication (2FA).
Register a passkey
The passkey module provides a method to trigger passkey registration. Hereโs an example:
When the user taps the button, the passkey registration flow will be triggered and the OS will prompt the user to register a passkey.
Authenticate with passkeys (1FA)
You can use passkeys as the primary authentication method. Hereโs how to implement passkey-based sign-in:
List and authenticate with passkeys (2FA)
For multi-factor authentication, you can use the following methods to list and authenticate with passkeys:
dynamicClient.passkeys.get()
- Retrieves all registered passkeys for the userdynamicClient.passkeys.authenticateMFA()
- Uses a registered passkey for multi-factor authentication
Hereโs a complete example for 2FA:
Conclusion
By following these steps, you can successfully integrate passkey functionality with the Dynamic SDK into your React Native app. This enables secure authentication for both primary login (1FA) and multi-factor authentication (2FA), providing users with a seamless and secure authentication experience across your mobile app.