@@ -4,11 +4,17 @@ sidebar_label: Auth0
44description : " Auth0 Login with Web3Auth | Documentation - Web3Auth"
55---
66
7+ import Tabs from " @theme/Tabs" ;
8+ import TabItem from " @theme/TabItem" ;
79import Tiles from " @theme/Tiles" ;
810
911import CustomConnectionOptions from " @site/static/images/dashboard/authentication-custom-connections.png" ;
1012import Auth0Connection from " @site/static/images/dashboard/auth0-connection.png" ;
1113
14+ import JwtLoginAuth0 from " ../../sdk/web/react/advanced/_custom-authentication-snippets/_jwt_login_auth0.mdx" ;
15+ import ImplicitLoginAuth0Google from " ../../sdk/web/react/advanced/_custom-authentication-snippets/_implicit_login_auth0_google.mdx" ;
16+ import ImplicitLoginAuth0Spa from " ../../sdk/web/react/advanced/_custom-authentication-snippets/_implicit_login_auth0_spa.mdx" ;
17+
1218Auth0 is a powerful authentication and authorization platform that enables developers to securely
1319manage user identities. Web3Auth offers native support for integrating Auth0 as a service provider,
1420allowing projects to leverage Auth0’s robust authentication mechanisms within the Web3Auth
@@ -75,16 +81,20 @@ export const Auth0Setup = [
7581To use this feature, developers must go to the ` Custom Connections ` tab in the
7682[ Web3Auth Dashboard] ( https://dashboard.web3auth.io ) .
7783
78- <div style = { { flexBasis: " 300px" , flexGrow: " 1" , textAlign: " center" }} >
84+ :::
85+
86+ <div style = { { display: " flex" , margin: " 20px 0" }} >
7987 <img
8088 src = { CustomConnectionOptions }
81- style = { { alignSelf: " center" , maxWidth: " 100%" }}
89+ style = { {
90+ maxWidth: " 800px" ,
91+ borderRadius: " 8px" ,
92+ boxShadow: " 0 2px 6px rgba(0, 0, 0, 0.1)" ,
93+ }}
8294 alt = " Custom Connection Options"
8395 />
8496</div >
8597
86- :::
87-
8898Follow these steps to create an Auth0 connection:
8999
901001 . Visit the [ Web3Auth Dashboard] ( https://dashboard.web3auth.io ) .
@@ -97,76 +107,182 @@ Follow these steps to create an Auth0 connection:
971078 . Enter ` Auth0 Domain ` .
981089 . Finally, click on the ` Add Connection ` button.
99109
100- <div style = { { flexBasis : " 300px " , flexGrow : " 1 " , textAlign: " left " }} >
110+ <div style = { { display : " flex " , margin : " 20px 0 " }} >
101111 <img
102112 src = { Auth0Connection }
103- style = { { alignSelf: " center" , maxWidth: " 100%" }}
113+ style = { {
114+ maxWidth: " 800px" ,
115+ borderRadius: " 8px" ,
116+ boxShadow: " 0 2px 6px rgba(0, 0, 0, 0.1)" ,
117+ }}
104118 alt = " Auth0 Connection"
105119 />
106120</div >
107121
108122## Usage
109123
110- ### Initialize Web3Auth
111-
112- Wrap your app with the ` Web3AuthProvider ` . This provider should be as close to the root of your
113- React tree as possible.
114-
115- ``` js title="Example: React + Vite (main.tsx)"
116- import { StrictMode } from " react" ;
117- import { createRoot } from " react-dom/client" ;
118- import " ./index.css" ;
119-
120- import { Web3AuthProvider , WEB3AUTH_NETWORK } from " @web3auth/modal/react" ;
121-
122- import App from " ./App.tsx" ;
123-
124- createRoot (document .getElementById (" root" )! ).render (
125- < StrictMode>
126- < Web3AuthProvider
127- config= {{
128- web3AuthOptions: {
129- clientId: " WEB3AUTH_CLIENT_ID" , // Replace with your Client ID
130- web3AuthNetwork: WEB3AUTH_NETWORK .SAPPHIRE_DEVNET ,
131- },
132- }}
133- >
134- < App / >
135- < / Web3AuthProvider>
136- < / StrictMode>
137- );
138- ```
139-
140124Since, the ` Auth0 Connection ` details are available from Dashboard, developers don't need to pass
141125any additional parameters to the ` Web3AuthProvider ` .
142126
143127> Follow our [ Quickstart Guide] ( /quick-start ) to setup the basic flow.
144128
145- ### Login with Auth0
146-
147- ``` jsx
148- import { useWeb3AuthConnect , WALLET_CONNECTORS , AUTH_CONNECTION } from " @web3auth/modal/react" ;
149- import { useAccount } from " wagmi" ;
150-
151- function LoginPage () {
152- const { connectTo } = useWeb3AuthConnect ();
153- const { address } = useAccount ();
154-
155- const loginWithAuth0 = async () => {
156- await connectTo (WALLET_CONNECTORS .AUTH , {
157- // focus-start
158- authConnectionId: " auth0-auth-connection-id" ,
159- authConnection: AUTH_CONNECTION .CUSTOM ,
160- // focus-end
161- });
162- };
163-
164- return (
165- < div>
166- < button onClick= {() => loginWithAuth0 ()}> Login with Auth0< / button>
167- < p> Address: {address}< / p>
168- {/* 0xA8b29d40d0FE6a0c153A5759B1f0059d8b7654c5 */ }
169- < / div>
129+ ### Web
130+
131+ <Tabs >
132+ <TabItem value = " implicit-spa" label = " Implicit Login (SPA)" >
133+ <ImplicitLoginAuth0Spa />
134+ </TabItem >
135+ <TabItem value = " implicit" label = " Implicit Login Auth0 Google" >
136+ <ImplicitLoginAuth0Google />
137+ </TabItem >
138+ <TabItem value = " jwt" label = " JWT Login with Auth0 SDK" >
139+ <JwtLoginAuth0 />
140+ </TabItem >
141+ </Tabs >
142+
143+ ### Android
144+
145+ ##### Create Web3Auth Instance
146+
147+ In your activity, create a ` Web3Auth ` instance with your Web3Auth project's configurations.
148+
149+ ``` kotlin
150+ web3Auth = Web3Auth (
151+ Web3AuthOptions (
152+ context = this ,
153+ clientId = getString(R .string.web3auth_project_id), // pass over your Web3Auth Client ID from Developer Dashboard
154+ network = Network .SAPPHIRE_MAINNET
155+ redirectUrl = Uri .parse(" {YOUR_APP_PACKAGE_NAME}://auth" ), // your app's redirect URL
156+ // focus-start
157+ loginConfig = hashMapOf(" jwt" to LoginConfigItem (
158+ verifier = " web3auth-auth0-demo" ,
159+ typeOfLogin = TypeOfLogin .JWT ,
160+ name = " Auth0 Login" ,
161+ clientId = getString(R .string.web3auth_auth0_client_id)
162+ )
163+ )
164+ // focus-end
165+ )
166+ )
167+
168+ // Handle user signing in when app is not alive
169+ web3Auth.setResultUrl(intent?.data)
170+ ```
171+
172+ ##### Logging in
173+
174+ Once initialized, you can use the ` web3Auth.login(LoginParams("{selectedLoginProvider}")) ` function
175+ to authenticate the user when they click the login button.
176+
177+ ``` kotlin
178+ private fun signIn () {
179+ val selectedLoginProvider = Provider .JWT // For Auth0, we use JWT
180+ val loginCompletableFuture: CompletableFuture <Web3AuthResponse > = web3Auth.login(
181+ // focus-start
182+ LoginParams (
183+ selectedLoginProvider,
184+ extraLoginOptions = ExtraLoginOptions (
185+ domain = " https://YOUR_AUTH0_DOMAIN" ,
186+ verifierIdField = " sub"
187+ )
188+ )
189+ // focus-end
190+ )
191+ }
192+ ```
193+
194+ When connecting, the ` login ` function takes the LoginParams arguments for the login. See the
195+ [ LoginParams] ( /sdk/mobile/pnp/android/usage#parameters ) for more details.
196+
197+ ### Flutter
198+
199+ ##### Create Web3Auth Instance
200+
201+ In your ` main.dart ` file, initialize the ` Web3AuthFlutter ` plugin at the very beginning such as in
202+ the overriden ` initState ` function
203+
204+ ``` dart
205+ Future<void> initPlatformState() async {
206+
207+ Uri redirectUrl;
208+ if (Platform.isAndroid) {
209+ redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth');
210+ // w3a://com.example.w3aflutter/auth
211+ } else if (Platform.isIOS) {
212+ redirectUrl = Uri.parse('{bundleId}://auth');
213+ // com.example.w3aflutter://openlogin
214+ } else {
215+ throw UnKnownException('Unknown platform');
216+ }
217+ // focus-start
218+ final loginConfig = HashMap<String, LoginConfigItem>();
219+ loginConfig['jwt'] = LoginConfigItem(
220+ verifier: "VERIFIER-NAME", // get it from web3auth dashboard
221+ typeOfLogin: TypeOfLogin.jwt,
222+ name: "Web3Auth Flutter Auth0 Example",
223+ clientId: "AUTH0-CLIENT-ID" // auth0 client id
170224 );
225+ // focus-end
226+
227+ await Web3AuthFlutter.init(Web3AuthOptions(
228+ clientId:'YOUR WEB3AUTH CLIENT ID FROM DASHBOARD',
229+ network: Network.sapphire_mainnet,
230+ redirectUri: redirectUrl,
231+ loginConfig: loginConfig
232+ ));
233+
234+ await Web3AuthFlutter.initialize();
235+ }
236+ ```
237+
238+ ##### Logging in
239+
240+ Once initialized, you can use the
241+ ` Web3AuthFlutter.login(LoginParams( loginProvider: Provider.google )) ` function to authenticate the
242+ user when they click the login button.
243+
244+ ``` dart
245+ Future<Web3AuthResponse> _withAuth0() {
246+ // focus-start
247+ return Web3AuthFlutter.login(LoginParams(
248+ loginProvider: Provider.jwt,
249+ mfaLevel: MFALevel.OPTIONAL,
250+ extraLoginOptions: ExtraLoginOptions(
251+ domain: 'YOUR_AUTH0_DOMAIN', // eg. https://torus.us.auth0.com
252+ verifierIdField: 'sub')));
253+ // focus-end
171254}
172255```
256+
257+ Read more about initializing the Flutter SDK [ here] ( /sdk/mobile/pnp/flutter/initialize ) .
258+
259+ ### React Native
260+
261+ ``` tsx
262+ const web3auth = new Web3Auth (WebBrowser , SecureStore , {
263+ clientId ,
264+ network: OPENLOGIN_NETWORK .SAPPHIRE_MAINNET , // SAPPHIRE_MAINNET or SAPPHIRE_DEVNET
265+ loginConfig: {
266+ // focus-start
267+ jwt: {
268+ verifier: " YOUR_AUTH0_VERIFIER_NAME" , // Please create a verifier on the developer dashboard and pass the name here
269+ typeOfLogin: " jwt" ,
270+ clientId: " AUTH0_CLIENT_ID_123ABcdefg4HiJKlMno4P5QR6stUvWXY" , // use your app client id you got from auth0
271+ },
272+ // focus-end
273+ },
274+ });
275+ ```
276+
277+ ``` tsx
278+ const web3authResponse = await web3auth .login ({
279+ redirectUrl: resolvedRedirectUrl ,
280+ // focus-start
281+ loginProvider: " jwt" ,
282+ extraLoginOptions: {
283+ domain: " https://YOUR-AUTH0-DOMAIN" , // Please append "https://" before your domain
284+ verifierIdField: " sub" , // For SMS & Email Passwordless, use "name" as verifierIdField
285+ },
286+ // focus-end
287+ });
288+ ```
0 commit comments