|
1 | 1 | # passage-flex-react-native |
2 | 2 |
|
3 | | -Native passkey authentication for your React Native and Expo apps. |
| 3 | +Passkey Flex provides passkey authentication support to existing authentication systems. It handles the hard parts of incorporating native passkey APIs and provides a simple, clean solution to take your authentication to the next level. |
| 4 | + |
| 5 | +Use the `passage-flex-react-native` SDK to implement Passkey Flex in your React Native app to use passkeys to register and authenticate, or as added security on secure user actions. |
| 6 | + |
| 7 | +For full documentation, including setting up a backend SDK, visit the [Passkey Flex documentation here](https://docs-v2.passage.id/flex). |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +### A Passkey Flex app |
| 12 | + |
| 13 | +1. Create a Passkey Flex app in the Passage Console at https://console.passage.id |
| 14 | +2. Add an Android and/or iOS app in the Native Apps section |
| 15 | +3. When you add your Native App info, you can generate the associated domain file for that app if you haven’t already created it yourself, as shown below: |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +### Hosted associated domains files |
| 20 | + |
| 21 | +In order for passkeys to work, you’ll need to associate your native app(s) with the public web domain you assigned to your Passkey Flex app. |
| 22 | + |
| 23 | +Android requires an `assetlinks.json` file configured and hosted (learn more [here](https://developer.android.com/identity/sign-in/credential-manager#add-support-dal)). |
| 24 | + |
| 25 | +Apple requires an `apple-app-site-association` file configured and hosted (learn more [here](https://developer.apple.com/documentation/Xcode/supporting-associated-domains)). |
4 | 26 |
|
5 | 27 | ## Installation |
6 | 28 |
|
7 | | -```sh |
8 | | -npm install passage-flex-react-native |
| 29 | +Install this package using npm: |
| 30 | + |
| 31 | +``` |
| 32 | +npm i --save @passageidentity/passage-flex-react-native |
9 | 33 | ``` |
10 | 34 |
|
| 35 | +## App configuration |
| 36 | + |
| 37 | +### Expo |
| 38 | + |
| 39 | +- Add plugin in app.json |
| 40 | + |
| 41 | + ```json |
| 42 | + "plugins": [ |
| 43 | + "@passageidentity/passage-flex-react-native", |
| 44 | + // ... |
| 45 | + ] |
| 46 | + ``` |
| 47 | + |
| 48 | +- Add `ASSOCIATED_DOMAIN` value to `.env` (in your app root) |
| 49 | + |
| 50 | + ``` |
| 51 | + ASSOCIATED_DOMAIN=example.com |
| 52 | + ``` |
| 53 | + |
| 54 | +- Run `npx expo prebuild` |
| 55 | + |
| 56 | +### Bare React Native |
| 57 | + |
| 58 | +See our [Passkey Complete documentation](https://docs.passage.id/mobile/cross-platform/cross-platform-passkey-configuration) for setting up a React Native app for passkeys and Passage. |
| 59 | + |
11 | 60 | ## Usage |
12 | 61 |
|
| 62 | +Import PassageFlex: |
| 63 | + |
| 64 | +```tsx |
| 65 | +import { PassageFlex } from '@passageidentity/passage-flex-react-native'; |
| 66 | +``` |
| 67 | + |
| 68 | +Initialize a Passage Flex instance using your `appId` found in [Passage Console](https://console.passage.id/): |
| 69 | + |
| 70 | +```tsx |
| 71 | +const passageFlex = new PassageFlex('YOUR_APP_ID'); |
| 72 | +``` |
| 73 | + |
| 74 | +### passageFlex.passkey.register |
| 75 | + |
| 76 | +To register a new user passkey, use the `passageFlex.passkey.register` method. |
| 77 | + |
| 78 | +Example: |
| 79 | + |
| 80 | +```tsx |
| 81 | +const onPressRegister = async () => { |
| 82 | + // 1. Get transaction id string from your backend. |
| 83 | + const transactionId = await getRegisterTransactionId("newuser@email.com"); |
| 84 | + // 2. Prompt user to create a passkey and get a Passage nonce value on success. |
| 85 | + const nonce = await passageFlex.passkey.register(transactionId); |
| 86 | + // 3. You can send this nonce to your backend to complete user registration. |
| 87 | +}; |
| 88 | +``` |
| 89 | + |
| 90 | +### passageFlex.passkey.authenticate |
| 91 | + |
| 92 | +To log in a user using a passkey, use the `passageFlex.passkey.authenticate` method. |
| 93 | + |
| 94 | +Example: |
| 95 | + |
| 96 | +```tsx |
| 97 | +const onPressLogIn = async () => { |
| 98 | + // 1. Get transaction id string from your backend. |
| 99 | + const transactionId = await getLogInTransactionId("existinguser@email.com"); |
| 100 | + // 2. Prompt user to create a passkey and get a Passage nonce value on success. |
| 101 | + const nonce = await passageFlex.passkey.authenticate(transactionId); |
| 102 | + // 3. You can send this nonce to your backend to complete user authentication. |
| 103 | +}; |
| 104 | +``` |
13 | 105 |
|
14 | | -```js |
15 | | -import { multiply } from 'passage-flex-react-native'; |
| 106 | +### passageFlex.passkey.isSupported |
16 | 107 |
|
17 | | -// ... |
| 108 | +You can check if a user’s device supports passkeys by calling `passageFlex.passkey.isSupported`: |
18 | 109 |
|
19 | | -const result = await multiply(3, 7); |
| 110 | +```tsx |
| 111 | +const deviceSupportsPasskeys = passageFlex.passkey.isSupported(); |
20 | 112 | ``` |
21 | 113 |
|
22 | 114 |
|
|
0 commit comments