Skip to content

Commit e844b36

Browse files
Merge pull request #21 from Web3Auth/feat/mfalevel
feat: mfa level
2 parents 090a0a4 + 25d5073 commit e844b36

File tree

11 files changed

+88
-18
lines changed

11 files changed

+88
-18
lines changed

Web3AuthReactNativeSDKDemo/App.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, {useState} from 'react';
33
import {StyleSheet, View, Text, Button} from 'react-native';
44
import Web3authReactNativeSdk, {
55
LoginProvider,
6+
MfaLevel,
67
Web3authNetwork,
78
} from '@web3auth/react-native-sdk';
89

@@ -72,6 +73,32 @@ export default function App() {
7273
}
7374
/>
7475
</View>
76+
<View style={styles.box}>
77+
<Button
78+
title="Login with Google with mandatory MFA"
79+
onPress={() =>
80+
Web3authReactNativeSdk.login({
81+
provider: LoginProvider.GOOGLE,
82+
mfaLevel: MfaLevel.MANDATORY,
83+
})
84+
.then(result => setLoginResult(JSON.stringify(result)))
85+
.catch(err => console.log(`error: ${err}`))
86+
}
87+
/>
88+
</View>
89+
<View style={styles.box}>
90+
<Button
91+
title="Login with Google with none MFA"
92+
onPress={() =>
93+
Web3authReactNativeSdk.login({
94+
provider: LoginProvider.GOOGLE,
95+
mfaLevel: MfaLevel.NONE,
96+
})
97+
.then(result => setLoginResult(JSON.stringify(result)))
98+
.catch(err => console.log(`error: ${err}`))
99+
}
100+
/>
101+
</View>
75102
<View style={styles.box}>
76103
<Button
77104
title="Logout"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "Web3AuthReactNativeSDKDemo",
2+
"name": "OpenLoginReactNativeSDKDemo2",
33
"displayName": "Web3AuthReactNativeSDKDemo"
44
}

Web3AuthReactNativeSDKDemo/ios/Podfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require_relative '../node_modules/react-native/scripts/react_native_pods'
22
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
33

4+
source 'https://github.com/CocoaPods/Specs.git'
5+
46
platform :ios, '13.0'
57

68
target 'OpenLoginReactNativeSDKDemo2' do
@@ -9,6 +11,8 @@ target 'OpenLoginReactNativeSDKDemo2' do
911

1012
pod 'OpenLogin', '1.0.0'
1113

14+
pod 'Web3Auth', '3.3.0'
15+
1216
use_react_native!(
1317
:path => config[:reactNativePath],
1418
# to enable hermes on iOS, change `false` to `true` and then install pods

Web3AuthReactNativeSDKDemo/ios/Podfile.lock

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ PODS:
338338
- React-jsi (= 0.66.3)
339339
- React-logger (= 0.66.3)
340340
- React-perflogger (= 0.66.3)
341-
- Web3Auth (3.1.0)
342-
- web3auth-react-native-sdk (2.0.0):
341+
- Web3Auth (3.3.0)
342+
- web3auth-react-native-sdk (2.0.1):
343343
- React-Core
344-
- Web3Auth (= 3.1.0)
344+
- Web3Auth (= 3.3.0)
345345
- Yoga (1.14.0)
346346
- YogaKit (1.18.1):
347347
- Yoga (~> 1.14)
@@ -400,11 +400,12 @@ DEPENDENCIES:
400400
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
401401
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
402402
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
403+
- Web3Auth (= 3.3.0)
403404
- "web3auth-react-native-sdk (from `../node_modules/@web3auth/react-native-sdk`)"
404405
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
405406

406407
SPEC REPOS:
407-
trunk:
408+
https://github.com/CocoaPods/Specs.git:
408409
- CocoaAsyncSocket
409410
- Flipper
410411
- Flipper-Boost-iOSX
@@ -530,11 +531,11 @@ SPEC CHECKSUMS:
530531
React-RCTVibration: 50cfe7049167cfc7e83ac5542c6fff0c76791a9b
531532
React-runtimeexecutor: bbbdb3d8fcf327c6e2249ee71b6ef1764b7dc266
532533
ReactCommon: 9bac022ab71596f2b0fde1268272543184c63971
533-
Web3Auth: 81df9a25d1ca80b10ac1f0447713297fc9b3aa48
534-
web3auth-react-native-sdk: ef9267bff580c28c7d578fbb10831f2b6ae43d1e
534+
Web3Auth: 83062b2ccc9b5882f44c02fa3464283f833c169f
535+
web3auth-react-native-sdk: a9b8461877ae8445fa8714db1f8d4d8f91eec839
535536
Yoga: 32a18c0e845e185f4a2a66ec76e1fd1f958f22fa
536537
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
537538

538-
PODFILE CHECKSUM: c2aa5d35f844d5e7a411cddb5201a81ba32e0078
539+
PODFILE CHECKSUM: 7a8d270f572e0a9fc7563775996efa33747cf55e
539540

540541
COCOAPODS: 1.11.2

Web3AuthReactNativeSDKDemo/metro.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require('path');
2-
const blacklist = require('metro-config/src/defaults/blacklist');
2+
const blacklist = require('metro-config/src/defaults/exclusionList');
33
const escape = require('escape-string-regexp');
44
const pak = require('../package.json');
55

Web3AuthReactNativeSDKDemo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"lint": "eslint ."
1111
},
1212
"dependencies": {
13+
"@web3auth/react-native-sdk": "../",
1314
"install": "^0.13.0",
1415
"npm": "^8.2.0",
15-
"@web3auth/react-native-sdk": "../",
1616
"react": "17.0.2",
1717
"react-native": "0.66.3"
1818
},

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ dependencies {
127127
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
128128
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
129129
implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.4'
130-
implementation 'org.torusresearch:web3auth-android-sdk:2.1.1'
130+
implementation 'org.torusresearch:web3auth-android-sdk:2.2.0'
131131
}
132132

133133
configurations.all {

android/src/main/java/com/web3authreactnativesdk/Web3authReactNativeSdkModule.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ class Web3authReactNativeSdkModule(reactContext: ReactApplicationContext) :
7676
?.hasKey("login_hint") == true
7777
) params.getMap("extraLoginOptions")?.getString("login_hint") else null
7878

79-
)
79+
),
80+
mfaLevel = getMFALevel(if (!params.hasKey("mfaLevel")) null else params.getString("mfaLevel"))
81+
8082
)
8183
val loginCF = web3auth.login(
8284
loginParams,
@@ -152,5 +154,16 @@ class Web3authReactNativeSdkModule(reactContext: ReactApplicationContext) :
152154
}
153155
}
154156

157+
fun getMFALevel(str: String?): MFALevel? {
158+
return when (str) {
159+
"default" -> MFALevel.DEFAULT
160+
"optional" -> MFALevel.OPTIONAL
161+
"mandatory" -> MFALevel.MANDATORY
162+
"none" -> MFALevel.NONE
163+
164+
else -> null
165+
}
166+
}
167+
155168
}
156169

ios/Web3authReactNativeSdk.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ class Web3authReactNativeSdk: NSObject {
2828
let redirectUrl = params["redirectUrl"] as? String
2929
let appState = params["appState"] as? String
3030
let login_hint = (params["extraLoginOptions"] as? [String: Any?])?["login_hint"] as? String
31+
let mfaLevel = getMfaLevel(params["mfaLevel"] as? String)
3132
if let w3a = web3auth {
3233
w3a.login(W3ALoginParams(
3334
loginProvider: provider,
3435
relogin: relogin,
3536
dappShare: dappShare,
36-
extraLoginOptions: login_hint == nil ? nil : ExtraLoginOptions(display: nil, prompt: nil, max_age: nil, ui_locales: nil, id_token_hint: nil, login_hint: login_hint, acr_values: nil, scope: nil, audience: nil, connection: nil, domain: nil, client_id: nil, redirect_uri: nil, leeway: nil, verifierIdField: nil, isVerifierIdCaseSensitive: nil),
37+
extraLoginOptions: login_hint == nil ? nil : ExtraLoginOptions(display: nil, prompt: nil, max_age: nil, ui_locales: nil, id_token_hint: nil, id_token: nil, login_hint: login_hint, acr_values: nil, scope: nil, audience: nil, connection: nil, domain: nil, client_id: nil, redirect_uri: nil, leeway: nil, verifierIdField: nil, isVerifierIdCaseSensitive: nil),
3738
redirectUrl: redirectUrl,
38-
appState: appState
39+
appState: appState,
40+
mfaLevel: mfaLevel
3941
)) {
4042
switch $0 {
4143
case .success(let result):
@@ -69,7 +71,7 @@ class Web3authReactNativeSdk: NSObject {
6971

7072
}
7173

72-
func getWeb3AuthProvider(_ str: String?) -> Web3AuthProvider?{
74+
func getWeb3AuthProvider(_ str: String?) -> Web3AuthProvider? {
7375
guard
7476
let unwrappedStr = str
7577
else {
@@ -93,3 +95,18 @@ func getWeb3AuthProvider(_ str: String?) -> Web3AuthProvider?{
9395
]
9496
return mapping[unwrappedStr]
9597
}
98+
99+
func getMfaLevel(_ str: String?) -> MFALevel? {
100+
guard
101+
let unwrappedStr = str
102+
else {
103+
return nil
104+
}
105+
let mapping: [String: MFALevel] = [
106+
"default": .DEFAULT,
107+
"optional": .OPTIONAL,
108+
"mandatory": .MANDATORY,
109+
"none": .NONE
110+
]
111+
return mapping[unwrappedStr]
112+
}

src/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ export interface LoginParams {
2929
redirectUrl?: string;
3030
appState?: string;
3131
extraLoginOptions?: { login_hint?: string };
32+
mfaLevel?: MfaLevel;
3233
}
3334

3435
type Web3authReactNativeSdkType = {
3536
init(params: InitParams): Promise<void>;
36-
login(params: { provider?: LoginProvider }): Promise<AuthState>;
37+
login(params: LoginParams): Promise<AuthState>;
3738
logout(params: {}): Promise<void>;
3839
};
3940

@@ -62,6 +63,13 @@ export enum Web3authNetwork {
6263
DEVELOPMENT = 'development',
6364
}
6465

66+
export enum MfaLevel {
67+
DEFAULT = 'default',
68+
OPTIONAL = 'optional',
69+
MANDATORY = 'mandatory',
70+
NONE = 'none',
71+
}
72+
6573
const { Web3authReactNativeSdk } = NativeModules;
6674

6775
const sdk = Web3authReactNativeSdk as Web3authReactNativeSdkType;

0 commit comments

Comments
 (0)