Skip to content

Commit acfcc98

Browse files
make enableMFA modular
1 parent 2e39df3 commit acfcc98

9 files changed

Lines changed: 218 additions & 179 deletions

File tree

docs/sdk/pnp/android/mfa.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description: "Web3Auth PnP Android SDK - Multi Factor Authentication | Documenta
88
import TabItem from "@theme/TabItem";
99
import Tabs from "@theme/Tabs";
1010
import MFAMinimumPlan from "@site/src/common/docs/_mfa_minimum_plan.mdx";
11+
import EnableMFAMethod from "@site/src/common/sdk/pnp/android/_enable-mfa.mdx";
1112

1213
At Web3Auth, we prioritize your security by offering Multi-Factor Authentication (MFA). MFA is an
1314
extra layer of protection that verifies your identity when accessing your account. To ensure
@@ -200,3 +201,7 @@ You can configure the order of MFA or enable/disable MFA type by passing the `mf
200201
)
201202
)
202203
```
204+
205+
## Using `enableMFA` method to trigger MFA setup flow for users
206+
207+
<EnableMFAMethod />

docs/sdk/pnp/android/usage.mdx

Lines changed: 3 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Tabs from "@theme/Tabs";
1010
import AndroidResponse from "@site/src/common/sdk/pnp/_userinfo_response.mdx";
1111
import LogOut from "@site/src/common/sdk/pnp/android/_logout.mdx";
1212
import SMSPasswordless from "@site/src/common/sdk/pnp/android/_sms_passwordless.mdx";
13+
import EnableMFAMethod from "@site/src/common/sdk/pnp/android/_enable-mfa.mdx";
1314

1415
Web3Auth's Android SDK is a set of libraries and tools that allow you to easily integrate Web3 with
1516
Android applications.
@@ -539,99 +540,7 @@ class MainActivity : AppCompatActivity() {
539540

540541
## Enable MFA for a user
541542

542-
The `enableMFA` method is used to trigger MFA setup flow for users. The method takes `LoginParams`
543-
which will used during custom verifiers. If you are using default login providers, you don't need to
544-
pass `LoginParams`. If you are using custom jwt verifiers, you need to pass the JWT token in
545-
`loginParams` as well.
546-
547-
<Tabs
548-
defaultValue="default-verifier"
549-
values={[
550-
{ label: "Default Verifier", value: "default-verifier" },
551-
{ label: "Custom JWT Verifier", value: "custom-jwt-verifier" },
552-
]}
553-
>
554-
555-
<TabItem value = "default-verifier">
556-
557-
```kotlin title="Usage"
558-
import android.widget.Button
559-
import com.web3auth.core.Web3Auth
560-
import android.os.Bundle
561-
562-
class MainActivity : AppCompatActivity() {
563-
private lateinit var web3Auth: Web3Auth
564-
565-
private fun enableMFA() {
566-
// highlight-next-line
567-
val completableFuture = web3Auth.enableMFA()
568-
569-
completableFuture.whenComplete{_, error ->
570-
if (error == null) {
571-
Log.d("MainActivity_Web3Auth", "Launched successfully")
572-
// Add your logic
573-
} else {
574-
// Add your logic on error
575-
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
576-
}
577-
}
578-
}
579-
580-
override fun onCreate(savedInstanceState: Bundle?) {
581-
...
582-
// Setup UI and event handlers
583-
val enableMFAButton = findViewById<Button>(R.id.enableMFAButton)
584-
enableMFAButton.setOnClickListener { enableMFA() }
585-
...
586-
}
587-
...
588-
}
589-
```
590-
591-
</TabItem>
592-
593-
<TabItem value="custom-jwt-verifier">
594-
```kotlin title="Usage"
595-
import android.widget.Button
596-
import com.web3auth.core.Web3Auth
597-
import android.os.Bundle
598-
599-
class MainActivity : AppCompatActivity() { private lateinit var web3Auth: Web3Auth
600-
601-
private fun enableMFA() {
602-
val loginParams = LoginParams(
603-
Provider.JWT,
604-
extraLoginOptions = ExtraLoginOptions(id_token = "your_jwt_token")
605-
)
606-
607-
// highlight-next-line
608-
val completableFuture = web3Auth.enableMFA(loginParams)
609-
610-
completableFuture.whenComplete{_, error ->
611-
if (error == null) {
612-
Log.d("MainActivity_Web3Auth", "Launched successfully")
613-
// Add your logic
614-
} else {
615-
// Add your logic on error
616-
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
617-
}
618-
}
619-
}
620-
621-
override fun onCreate(savedInstanceState: Bundle?) {
622-
...
623-
// Setup UI and event handlers
624-
val enableMFAButton = findViewById<Button>(R.id.enableMFAButton)
625-
enableMFAButton.setOnClickListener { enableMFA() }
626-
...
627-
}
628-
...
629-
630-
}
631-
632-
````
633-
</TabItem>
634-
</Tabs>
543+
<EnableMFAMethod />
635544

636545
## Launch Wallet Services
637546

@@ -689,7 +598,7 @@ data class ChainConfig(
689598
val ticker: String?,
690599
val tickerName: String? = null,
691600
)
692-
````
601+
```
693602

694603
</TabItem>
695604
</Tabs>

docs/sdk/pnp/flutter/mfa.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description: "Web3Auth PnP Flutter SDK - Multi Factor Authentication | Documenta
88
import TabItem from "@theme/TabItem";
99
import Tabs from "@theme/Tabs";
1010
import MFAMinimumPlan from "@site/src/common/docs/_mfa_minimum_plan.mdx";
11+
import EnableMFAMethod from "@site/src/common/sdk/pnp/flutter/_enable-mfa.mdx";
1112

1213
At Web3Auth, we prioritize your security by offering Multi-Factor Authentication (MFA). MFA is an
1314
extra layer of protection that verifies your identity when accessing your account. To ensure
@@ -232,3 +233,7 @@ Future<void> initWeb3Auth() async {
232233
await Web3AuthFlutter.initialize();
233234
}
234235
```
236+
237+
## Using `enableMFA` method to trigger MFA setup flow for users
238+
239+
<EnableMFAMethod />

docs/sdk/pnp/flutter/usage.mdx

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import TabItem from "@theme/TabItem";
99
import Tabs from "@theme/Tabs";
1010
import FlutterResponse from "@site/src/common/sdk/pnp/_userinfo_response.mdx";
1111
import SMSPasswordless from "@site/src/common/sdk/pnp/flutter/_sms_passwordless.mdx";
12+
import EnableMFAMethod from "@site/src/common/sdk/pnp/flutter/_enable-mfa.mdx";
1213

1314
## Logging in a User
1415

@@ -514,45 +515,7 @@ Get started with a sample app found
514515

515516
## Enable MFA for a user
516517

517-
The `enableMFA` method is used to trigger MFA setup flow for users. The method takes `LoginParams`
518-
which will used during custom verifiers. If you are using default login providers, you don't need to
519-
pass `LoginParams`. If you are using custom jwt verifiers, you need to pass the JWT token in
520-
`loginParams` as well.
521-
522-
<Tabs
523-
defaultValue="default-verifier"
524-
values={[
525-
{ label: "Default Verifier", value: "default-verifier" },
526-
{ label: "Custom JWT Verifier", value: "custom-jwt-verifier" },
527-
]}
528-
>
529-
530-
<TabItem value="default-verifier">
531-
```dart title="Usage"
532-
try {
533-
// highlight-next-line
534-
await Web3AuthFlutter.enableMFA();
535-
} on UserCancelledException {
536-
log("User cancelled.");
537-
} catch(e) {
538-
log("Unknown exception occurred");
539-
}
540-
```
541-
</ TabItem>
542-
543-
<TabItem value="custom-jwt-verifier">
544-
```dart title="Usage"
545-
try {
546-
547-
final loginParams = LoginParams( loginProvider: Provider.jwt, extraLoginOptions: ExtraLoginOptions(
548-
id_token: "YOUR_JWT_TOKEN", ) );
549-
550-
// highlight-next-line await Web3AuthFlutter.enableMFA(loginParams); } on UserCancelledException {
551-
log("User cancelled."); } catch(e) { log("Unknown exception occurred"); }
552-
553-
````
554-
</ TabItem>
555-
</ Tabs>
518+
<EnableMFAMethod />
556519

557520
## Launch Wallet Services
558521

@@ -636,7 +599,7 @@ class ChainConfig {
636599
};
637600
}
638601
}
639-
````
602+
```
640603

641604
</TabItem>
642605
</Tabs>

docs/sdk/pnp/ios/mfa.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description: "Web3Auth PnP iOS SDK - Multi Factor Authentication | Documentation
88
import TabItem from "@theme/TabItem";
99
import Tabs from "@theme/Tabs";
1010
import MFAMinimumPlan from "@site/src/common/docs/_mfa_minimum_plan.mdx";
11+
import EnableMFAMethod from "@site/src/common/sdk/pnp/ios/_enable-mfa.mdx";
1112

1213
The Multi Factor Authentication feature refers to the ability of the user to create a backup share
1314
(recovery phrase). This helps them login into a new device and also to recover their account if they
@@ -228,3 +229,7 @@ let result = try await Web3Auth(
228229
curve: .SECP256K1
229230
))
230231
```
232+
233+
## Using `enableMFA` method to trigger MFA setup flow for users
234+
235+
<EnableMFAMethod />

docs/sdk/pnp/ios/usage.mdx

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import IosResponse from "@site/src/common/sdk/pnp/_userinfo_response.mdx";
1010
import TabItem from "@theme/TabItem";
1111
import Tabs from "@theme/Tabs";
1212
import SMSPasswordless from "@site/src/common/sdk/pnp/ios/_sms_passwordless.mdx";
13+
import EnableMFAMethod from "@site/src/common/sdk/pnp/ios/_enable-mfa.mdx";
1314

1415
## Logging in a User
1516

@@ -430,50 +431,7 @@ await Web3Auth().logout()
430431

431432
## Enable MFA for a user
432433

433-
The `enableMFA` method is used to trigger MFA setup flow for users. The method takes
434-
`W3ALoginParams` which will used during custom verifiers. If you are using default login providers,
435-
you don't need to pass `W3ALoginParams`. If you are using custom jwt verifiers, you need to pass the
436-
valid JWT token in `W3ALoginParams` as well.
437-
438-
<Tabs
439-
defaultValue="default-verifier"
440-
values={[
441-
{ label: "Default Verifier", value: "default-verifier" },
442-
{ label: "Custom JWT Verifier", value: "custom-jwt-verifier" },
443-
]}
444-
>
445-
446-
<TabItem value = "default-verifier">
447-
448-
```swift title="Usage"
449-
do {
450-
// highlight-next-line
451-
let isMFAEnabled = try await self.web3Auth.enableMFA()
452-
} catch {
453-
print(error.localizedDescription)
454-
// Handle Error
455-
}
456-
```
457-
458-
</TabItem>
459-
460-
<TabItem value = "custom-jwt-verifier">
461-
```swift title="Usage"
462-
do {
463-
let loginParams = W3ALoginParams(
464-
.JWT,
465-
extraLoginOptions: .init(id_token: "your_jwt_token")
466-
)
467-
468-
// highlight-next-line
469-
let isMFAEnabled = try await self.web3Auth.enableMFA(loginParams)
470-
471-
} catch { print(error.localizedDescription) // Handle Error }
472-
473-
````
474-
</TabItem>
475-
476-
</Tabs>
434+
<EnableMFAMethod />
477435

478436
## Launch Wallet Services
479437

@@ -534,7 +492,7 @@ public struct ChainConfig: Codable {
534492
}
535493
}
536494

537-
````
495+
```
538496

539497
</TabItem>
540498
</Tabs>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import TabItem from "@theme/TabItem";
2+
import Tabs from "@theme/Tabs";
3+
4+
The `enableMFA` method is used to trigger MFA setup flow for users. The method takes `LoginParams`
5+
which will used during custom verifiers. If you are using default login providers, you don't need to
6+
pass `LoginParams`. If you are using custom jwt verifiers, you need to pass the JWT token in
7+
`loginParams` as well.
8+
9+
<Tabs
10+
defaultValue="default-verifier"
11+
values={[
12+
{ label: "Default Verifier", value: "default-verifier" },
13+
{ label: "Custom JWT Verifier", value: "custom-jwt-verifier" },
14+
]}
15+
>
16+
17+
<TabItem value = "default-verifier">
18+
19+
```kotlin title="Usage"
20+
import android.widget.Button
21+
import com.web3auth.core.Web3Auth
22+
import android.os.Bundle
23+
24+
class MainActivity : AppCompatActivity() {
25+
private lateinit var web3Auth: Web3Auth
26+
27+
private fun enableMFA() {
28+
// highlight-next-line
29+
val completableFuture = web3Auth.enableMFA()
30+
31+
completableFuture.whenComplete{_, error ->
32+
if (error == null) {
33+
Log.d("MainActivity_Web3Auth", "Launched successfully")
34+
// Add your logic
35+
} else {
36+
// Add your logic on error
37+
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
38+
}
39+
}
40+
}
41+
42+
override fun onCreate(savedInstanceState: Bundle?) {
43+
...
44+
// Setup UI and event handlers
45+
val enableMFAButton = findViewById<Button>(R.id.enableMFAButton)
46+
enableMFAButton.setOnClickListener { enableMFA() }
47+
...
48+
}
49+
...
50+
}
51+
```
52+
53+
</TabItem>
54+
55+
<TabItem value="custom-jwt-verifier">
56+
```kotlin title="Usage"
57+
import android.widget.Button
58+
import com.web3auth.core.Web3Auth
59+
import android.os.Bundle
60+
61+
class MainActivity : AppCompatActivity() { private lateinit var web3Auth: Web3Auth
62+
63+
private fun enableMFA() {
64+
val loginParams = LoginParams(
65+
Provider.JWT,
66+
extraLoginOptions = ExtraLoginOptions(id_token = "your_jwt_token")
67+
)
68+
69+
// highlight-next-line
70+
val completableFuture = web3Auth.enableMFA(loginParams)
71+
72+
completableFuture.whenComplete{_, error ->
73+
if (error == null) {
74+
Log.d("MainActivity_Web3Auth", "Launched successfully")
75+
// Add your logic
76+
} else {
77+
// Add your logic on error
78+
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
79+
}
80+
}
81+
}
82+
83+
override fun onCreate(savedInstanceState: Bundle?) {
84+
...
85+
// Setup UI and event handlers
86+
val enableMFAButton = findViewById<Button>(R.id.enableMFAButton)
87+
enableMFAButton.setOnClickListener { enableMFA() }
88+
...
89+
}
90+
...
91+
92+
}
93+
94+
```
95+
</TabItem>
96+
</Tabs>
97+
```

0 commit comments

Comments
 (0)