|
1 | | -# React Native SDK for Web3Auth |
| 1 | +# Web3Auth React Native SDK |
2 | 2 |
|
3 | | -## Installation |
| 3 | +Web3Auth is where passwordless auth meets non-custodial key infrastructure for Web3 apps and wallets. By aggregating OAuth (Google, Twitter, Discord) logins, different wallets and innovative Multi Party Computation (MPC) - Web3Auth provides a seamless login experience to every user on your application. |
| 4 | + |
| 5 | +## 📖 Documentation |
| 6 | + |
| 7 | +Checkout the official [Web3Auth Documentation](https://web3auth.io/docs) and [SDK Reference](https://web3auth.io/docs/sdk/react-native/) to get started! |
| 8 | + |
| 9 | +## 💡 Features |
| 10 | +- Plug and Play, OAuth based Web3 Authentication Service |
| 11 | +- Fully decentralized, non-custodial key infrastructure |
| 12 | +- End to end Whitelabelable solution |
| 13 | +- Threshold Cryptography based Key Reconstruction |
| 14 | +- Multi Factor Authentication Setup & Recovery (Includes password, backup phrase, device factor editing/deletion etc) |
| 15 | +- Support for WebAuthn & Passwordless Login |
| 16 | +- Support for connecting to multiple wallets |
| 17 | +- DApp Active Session Management |
| 18 | + |
| 19 | +...and a lot more |
| 20 | + |
| 21 | +## ⏪ Requirements |
| 22 | + |
| 23 | +- For iOS, only iOS 12+ supported since we requires ASWebAuthenticationSession. |
| 24 | + |
| 25 | +- For Android, Custom Tab support is required. |
| 26 | + |
| 27 | +## Selecting your Workflow |
| 28 | + |
| 29 | +In React Native, you have the choice to use one of the following workflows: |
| 30 | + |
| 31 | +- **Bare Workflow**: Your React Native app is entirely built on your own machine. You can customize your app with Swift/Kotlin native modules. |
| 32 | +- **Expo Managed Workflow**: Your React Native Expo app is built on your Expo's cloud, so you don't have control over the native modules used in the app. |
| 33 | + |
| 34 | +## ⚡ Installation |
4 | 35 |
|
5 | 36 | ```sh |
6 | 37 | npm install @web3auth/react-native-sdk |
7 | 38 | ``` |
8 | 39 |
|
| 40 | +## 🌟 Configuration |
| 41 | + |
| 42 | +### Configure your Web3Auth project |
| 43 | + |
| 44 | +Hop on to the [Web3Auth Dashboard](https://dashboard.web3auth.io/) and create a new project. Use the Client ID of the project to start your integration. |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +- Add `{YOUR_APP_PACKAGE_NAME}://auth` to **Whitelist URLs**. |
| 49 | + |
| 50 | +- Copy the Project ID for usage later. |
| 51 | + |
| 52 | +### Expo Managed Workflow |
| 53 | + |
| 54 | +When using our SDK with a Expo-based React Native app (aka managed workflow, you have to install the `expo-web-browser` package as a `WebBrowser` implementation.) |
| 55 | + |
| 56 | +```sh |
| 57 | +expo install expo-web-browser |
| 58 | +``` |
| 59 | + |
9 | 60 | To allow the SDK to work with exported Expo Android apps, you need to place a designated scheme into `app.json`, like below: |
10 | 61 |
|
11 | 62 | ```js |
12 | | - "scheme": "web3authreactnativesdkexample", |
| 63 | +{ |
| 64 | + "expo": { |
| 65 | + "scheme": "web3authexposample" |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +### Bare workflow Configuration |
| 71 | + |
| 72 | +When using our SDK with a bare workflow React Native app, you have to install a `WebBrowser` implementation made by us. |
| 73 | + |
| 74 | +```sh |
| 75 | +npm install --save @toruslabs/react-native-web-browser |
13 | 76 | ``` |
14 | 77 |
|
15 | | -## Usage |
| 78 | +#### Android |
16 | 79 |
|
17 | | -Please see [App.tsx](./example/App.tsx) for detailed example. |
| 80 | +- The `scheme` parameter in the `redirectUrl` is specificable, and has to be added into the `AndroidManifest.xml`. |
| 81 | + |
| 82 | +```xml |
| 83 | +<data android:scheme="web3authrnexample" /> |
| 84 | +``` |
| 85 | + |
| 86 | +#### iOS |
| 87 | + |
| 88 | +- The `scheme` parameter in the `redirectUrl` is specificable here as well, however, it does not need to be added as a iOS Custom URL Scheme. You may add the `scheme` to your iOS `Info.plist`, but it is not required. |
| 89 | + |
| 90 | +#### Register the URL scheme you intended to use for redirection |
| 91 | + |
| 92 | +- In the Web3Auth Developer Dashboard, add the URL scheme you intended to use for redirection to the **Whitelist URLs** section. |
| 93 | + |
| 94 | +For example, the scheme mentioned is `web3authrnexample` and the `redirectUrl` mentioned is `${scheme}://openlogin`, we will whitelist: |
| 95 | + |
| 96 | +``` |
| 97 | +web3authrnexample://openlogin |
| 98 | +``` |
| 99 | + |
| 100 | +## 💥 Initialization & Usage |
| 101 | + |
| 102 | +In your sign-in activity', create an `Web3Auth` instance with your Web3Auth project's configurations and |
| 103 | +configure it like this: |
| 104 | + |
| 105 | +### Expo Managed Workflow |
18 | 106 |
|
19 | 107 | ```js |
20 | | -import * as WebBrowser from "@toruslabs/react-native-web-browser"; |
21 | | -// or import * as WebBrowser from "expo-web-browser"; (for expo) |
| 108 | +import * as WebBrowser from 'expo-web-browser'; |
| 109 | +import Web3Auth, { LOGIN_PROVIDER, OPENLOGIN_NETWORK } from "@web3auth/react-native-sdk"; |
22 | 110 |
|
23 | 111 | const web3auth = new Web3Auth(WebBrowser, { |
24 | | - clientId: "BC5bANkU4-fil7C5s1uKzRfF0VGqbuaxDQiLnQ8WgF7SEA32lGegAhu7dk4dZf3Rk397blIvfWytXwsRvs9dOaQ", |
25 | | - network: Network.TESTNET, |
| 112 | + clientId, |
| 113 | + network: OPENLOGIN_NETWORK.TESTNET, // or other networks |
26 | 114 | }); |
27 | | -const state = await web3auth.login({ |
28 | | - loginProvider: LoginProvider.GOOGLE, |
29 | | - redirectUrl: resolvedRedirectUrl, |
| 115 | +const info = await web3auth.login({ |
| 116 | + loginProvider: LOGIN_PROVIDER.GOOGLE, |
| 117 | + redirectUrl: resolvedRedirectUrl, |
| 118 | + mfaLevel: 'mandatory', // optional |
| 119 | + curve: 'secp256k1', // optional |
30 | 120 | }); |
31 | 121 | ``` |
32 | 122 |
|
33 | | -## License |
| 123 | +### Bare Workflow |
| 124 | + |
| 125 | +```js |
| 126 | +import * as WebBrowser from '@toruslabs/react-native-web-browser'; |
| 127 | +import Web3Auth, { LOGIN_PROVIDER, OPENLOGIN_NETWORK } from "@web3auth/react-native-sdk"; |
| 128 | + |
| 129 | +const web3auth = new Web3Auth(WebBrowser, { |
| 130 | + clientId, |
| 131 | + network: OPENLOGIN_NETWORK.TESTNET, // or other networks |
| 132 | +}); |
| 133 | +const info = await web3auth.login({ |
| 134 | + loginProvider: LOGIN_PROVIDER.GOOGLE, |
| 135 | + redirectUrl: resolvedRedirectUrl, |
| 136 | + mfaLevel: 'mandatory', // optional |
| 137 | + curve: 'secp256k1', // optional |
| 138 | +}); |
| 139 | +``` |
| 140 | + |
| 141 | +## 🩹 Examples |
| 142 | + |
| 143 | +Checkout the examples for your preferred blockchain and platform in our [examples repository](https://github.com/Web3Auth/examples/) |
| 144 | + |
| 145 | +## 🌐 Demo |
| 146 | + |
| 147 | +Checkout the [Web3Auth Demo](https://demo-app.web3auth.io/) to see how Web3Auth can be used in an application. |
| 148 | + |
| 149 | +Further checkout the [example folder](https://github.com/Web3Auth/web3auth-react-native-sdk/tree/master/example) within this repository, which contains a sample app. |
| 150 | + |
| 151 | +## 💬 Troubleshooting and Discussions |
34 | 152 |
|
35 | | -MIT |
| 153 | +- Have a look at our [GitHub Discussions](https://github.com/Web3Auth/Web3Auth/discussions?discussions_q=sort%3Atop) to see if anyone has any questions or issues you might be having. |
| 154 | +- Checkout our [Troubleshooting Documentation Page](https://web3auth.io/docs/troubleshooting) to know the common issues and solutions |
| 155 | +- Join our [Discord](https://discord.gg/web3auth) to join our community and get private integration support or help with your integration. |
0 commit comments