@react-native-firebase/auth 26.0.0 → 26.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/RNFBAuth.podspec +2 -1
- package/android/src/main/java/io/invertase/firebase/auth/NativeRNFBTurboAuth.java +9 -1
- package/android/src/main/java/io/invertase/firebase/auth/generated/java/com/facebook/fbreact/specs/NativeRNFBTurboAuthSpec.java +1 -1
- package/android/src/main/java/io/invertase/firebase/auth/generated/jni/RNFBAuthTurboModules-generated.cpp +2 -2
- package/android/src/main/java/io/invertase/firebase/auth/generated/jni/react/renderer/components/RNFBAuthTurboModules/RNFBAuthTurboModulesJSI-generated.cpp +3 -2
- package/android/src/main/java/io/invertase/firebase/auth/generated/jni/react/renderer/components/RNFBAuthTurboModules/RNFBAuthTurboModulesJSI.h +5 -5
- package/dist/module/credentials/OAuthCredential.js +22 -1
- package/dist/module/credentials/OAuthCredential.js.map +1 -1
- package/dist/module/index.js +6 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/providers/AppleAuthProvider.js +17 -4
- package/dist/module/providers/AppleAuthProvider.js.map +1 -1
- package/dist/module/providers/OAuthProvider.js +4 -2
- package/dist/module/providers/OAuthProvider.js.map +1 -1
- package/dist/module/types/auth.js +8 -0
- package/dist/module/types/auth.js.map +1 -1
- package/dist/module/version.js +1 -1
- package/dist/module/web/RNFBAuthModule.js +13 -11
- package/dist/module/web/RNFBAuthModule.js.map +1 -1
- package/dist/typescript/lib/credentials/OAuthCredential.d.ts +6 -0
- package/dist/typescript/lib/credentials/OAuthCredential.d.ts.map +1 -1
- package/dist/typescript/lib/index.d.ts.map +1 -1
- package/dist/typescript/lib/providers/AppleAuthProvider.d.ts +10 -3
- package/dist/typescript/lib/providers/AppleAuthProvider.d.ts.map +1 -1
- package/dist/typescript/lib/providers/OAuthProvider.d.ts.map +1 -1
- package/dist/typescript/lib/types/auth.d.ts +26 -0
- package/dist/typescript/lib/types/auth.d.ts.map +1 -1
- package/dist/typescript/lib/types/internal.d.ts +1 -1
- package/dist/typescript/lib/types/internal.d.ts.map +1 -1
- package/dist/typescript/lib/version.d.ts +1 -1
- package/dist/typescript/lib/web/RNFBAuthModule.d.ts +3 -1
- package/dist/typescript/lib/web/RNFBAuthModule.d.ts.map +1 -1
- package/ios/RNFBAuth/RNFBAuthHelper.h +338 -0
- package/ios/RNFBAuth/RNFBAuthHelper.m +2221 -0
- package/ios/RNFBAuth/RNFBAuthModule.h +7 -64
- package/ios/RNFBAuth/RNFBAuthModule.mm +177 -1638
- package/ios/generated/RNFBAuthTurboModules/RNFBAuthTurboModules-generated.mm +2 -2
- package/ios/generated/RNFBAuthTurboModules/RNFBAuthTurboModules.h +1 -0
- package/ios/generated/RNFBAuthTurboModulesJSI-generated.cpp +3 -2
- package/ios/generated/RNFBAuthTurboModulesJSI.h +5 -5
- package/lib/credentials/OAuthCredential.ts +44 -0
- package/lib/index.ts +13 -1
- package/lib/providers/AppleAuthProvider.ts +21 -5
- package/lib/providers/OAuthProvider.ts +2 -0
- package/lib/types/auth.ts +27 -0
- package/lib/types/internal.ts +2 -0
- package/lib/version.ts +1 -1
- package/lib/web/RNFBAuthModule.ts +34 -23
- package/package.json +7 -8
- package/plugin/build/ios/urlTypes.js +1 -1
- package/plugin/src/ios/urlTypes.ts +1 -1
- package/plugin/tsconfig.json +2 -1
- package/specs/NativeRNFBTurboAuth.ts +2 -0
|
@@ -15,59 +15,14 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
#import "RNFBApp/RNFBAppModule.h"
|
|
23
|
-
#import "RNFBApp/RNFBSharedUtils.h"
|
|
18
|
+
// This module intentionally has no Firebase imports -- see RNFBAuthHelper.h /
|
|
19
|
+
// RNFBAuthModule.h for why. Every Firebase Auth SDK call is routed through the
|
|
20
|
+
// plain Objective-C RNFBAuthHelper class instead, which can safely `@import
|
|
21
|
+
// FirebaseAuth` because it compiles as ObjC, not ObjC++.
|
|
24
22
|
#import "RNFBAuthModule.h"
|
|
23
|
+
#import "RNFBAuthHelper.h"
|
|
25
24
|
#import "RNFBAuthTurboModules.h"
|
|
26
25
|
|
|
27
|
-
static void RNFBAuthThrowSyncErrorWithCode(NSString *code, NSString *message) {
|
|
28
|
-
@throw [NSException exceptionWithName:code
|
|
29
|
-
reason:message
|
|
30
|
-
userInfo:@{@"code" : code, @"message" : message}];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static NSString *const keyIOS = @"iOS";
|
|
34
|
-
static NSString *const keyUrl = @"url";
|
|
35
|
-
static NSString *const keyUid = @"uid";
|
|
36
|
-
static NSString *const keyUser = @"user";
|
|
37
|
-
static NSString *const keyEmail = @"email";
|
|
38
|
-
static NSString *const keyAndroid = @"android";
|
|
39
|
-
static NSString *const keyProfile = @"profile";
|
|
40
|
-
static NSString *const keyNewUser = @"isNewUser";
|
|
41
|
-
static NSString *const keyUsername = @"username";
|
|
42
|
-
static NSString *const keyMultiFactor = @"multiFactor";
|
|
43
|
-
static NSString *const keyPhotoUrl = @"photoURL";
|
|
44
|
-
static NSString *const keyBundleId = @"bundleId";
|
|
45
|
-
static NSString *const keyInstallApp = @"installApp";
|
|
46
|
-
static NSString *const keyProviderId = @"providerId";
|
|
47
|
-
static NSString *const keyPhoneNumber = @"phoneNumber";
|
|
48
|
-
static NSString *const keyDisplayName = @"displayName";
|
|
49
|
-
static NSString *const keyPackageName = @"packageName";
|
|
50
|
-
static NSString *const keyMinVersion = @"minimumVersion";
|
|
51
|
-
static NSString *const constAppLanguage = @"APP_LANGUAGE";
|
|
52
|
-
static NSString *const constAppUser = @"APP_USER";
|
|
53
|
-
static NSString *const keyHandleCodeInApp = @"handleCodeInApp";
|
|
54
|
-
static NSString *const keyLinkDomain = @"linkDomain";
|
|
55
|
-
static NSString *const keyAdditionalUserInfo = @"additionalUserInfo";
|
|
56
|
-
static NSString *const AUTH_STATE_CHANGED_EVENT = @"auth_state_changed";
|
|
57
|
-
static NSString *const AUTH_ID_TOKEN_CHANGED_EVENT = @"auth_id_token_changed";
|
|
58
|
-
static NSString *const PHONE_AUTH_STATE_CHANGED_EVENT = @"phone_auth_state_changed";
|
|
59
|
-
|
|
60
|
-
static __strong NSMutableDictionary *authStateHandlers;
|
|
61
|
-
static __strong NSMutableDictionary *idTokenHandlers;
|
|
62
|
-
static __strong NSMutableDictionary *emulatorConfigs;
|
|
63
|
-
// Used for caching credentials between method calls.
|
|
64
|
-
static __strong NSMutableDictionary<NSString *, FIRAuthCredential *> *credentials;
|
|
65
|
-
#if TARGET_OS_IOS
|
|
66
|
-
static __strong NSMutableDictionary<NSString *, FIRMultiFactorResolver *> *cachedResolver;
|
|
67
|
-
static __strong NSMutableDictionary<NSString *, FIRMultiFactorSession *> *cachedSessions;
|
|
68
|
-
static __strong NSMutableDictionary<NSString *, FIRTOTPSecret *> *cachedTotpSecrets;
|
|
69
|
-
#endif
|
|
70
|
-
|
|
71
26
|
@implementation RNFBAuthModule
|
|
72
27
|
#pragma mark -
|
|
73
28
|
#pragma mark Module Setup
|
|
@@ -83,138 +38,51 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
83
38
|
return std::make_shared<facebook::react::NativeRNFBTurboAuthSpecJSI>(params);
|
|
84
39
|
}
|
|
85
40
|
|
|
86
|
-
- (id)init {
|
|
87
|
-
self = [super init];
|
|
88
|
-
static dispatch_once_t onceToken;
|
|
89
|
-
dispatch_once(&onceToken, ^{
|
|
90
|
-
authStateHandlers = [[NSMutableDictionary alloc] init];
|
|
91
|
-
idTokenHandlers = [[NSMutableDictionary alloc] init];
|
|
92
|
-
emulatorConfigs = [[NSMutableDictionary alloc] init];
|
|
93
|
-
credentials = [[NSMutableDictionary alloc] init];
|
|
94
|
-
#if TARGET_OS_IOS
|
|
95
|
-
cachedResolver = [[NSMutableDictionary alloc] init];
|
|
96
|
-
cachedSessions = [[NSMutableDictionary alloc] init];
|
|
97
|
-
cachedTotpSecrets = [[NSMutableDictionary alloc] init];
|
|
98
|
-
#endif
|
|
99
|
-
});
|
|
100
|
-
return self;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
41
|
- (void)dealloc {
|
|
104
42
|
[self invalidate];
|
|
105
43
|
}
|
|
106
44
|
|
|
107
45
|
- (void)invalidate {
|
|
108
|
-
|
|
109
|
-
FIRApp *firebaseApp = [RCTConvert firAppFromString:key];
|
|
110
|
-
|
|
111
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
112
|
-
removeAuthStateDidChangeListener:[authStateHandlers valueForKey:key]];
|
|
113
|
-
}
|
|
114
|
-
[authStateHandlers removeAllObjects];
|
|
115
|
-
|
|
116
|
-
for (NSString *key in idTokenHandlers) {
|
|
117
|
-
FIRApp *firebaseApp = [RCTConvert firAppFromString:key];
|
|
118
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
119
|
-
removeIDTokenDidChangeListener:[idTokenHandlers valueForKey:key]];
|
|
120
|
-
}
|
|
121
|
-
[idTokenHandlers removeAllObjects];
|
|
122
|
-
|
|
123
|
-
[credentials removeAllObjects];
|
|
124
|
-
#if TARGET_OS_IOS
|
|
125
|
-
[cachedResolver removeAllObjects];
|
|
126
|
-
[cachedSessions removeAllObjects];
|
|
127
|
-
[cachedTotpSecrets removeAllObjects];
|
|
128
|
-
#endif
|
|
46
|
+
[RNFBAuthHelper invalidate];
|
|
129
47
|
}
|
|
130
48
|
|
|
131
49
|
#pragma mark -
|
|
132
50
|
#pragma mark Firebase Auth Methods
|
|
133
51
|
|
|
134
52
|
- (void)addAuthStateListener:(NSString *)appName {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (![authStateHandlers valueForKey:firebaseApp.name]) {
|
|
138
|
-
FIRAuthStateDidChangeListenerHandle newListenerHandle = [[FIRAuth authWithApp:firebaseApp]
|
|
139
|
-
addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) {
|
|
140
|
-
if (user != nil) {
|
|
141
|
-
[RNFBSharedUtils sendJSEventForApp:firebaseApp
|
|
142
|
-
name:AUTH_STATE_CHANGED_EVENT
|
|
143
|
-
body:@{keyUser : [self firebaseUserToDict:user]}];
|
|
144
|
-
} else {
|
|
145
|
-
[RNFBSharedUtils sendJSEventForApp:firebaseApp name:AUTH_STATE_CHANGED_EVENT body:@{}];
|
|
146
|
-
}
|
|
147
|
-
}];
|
|
148
|
-
authStateHandlers[firebaseApp.name] = newListenerHandle;
|
|
149
|
-
}
|
|
53
|
+
[RNFBAuthHelper addAuthStateListener:appName];
|
|
150
54
|
}
|
|
151
55
|
|
|
152
56
|
- (void)removeAuthStateListener:(NSString *)appName {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if ([authStateHandlers valueForKey:firebaseApp.name]) {
|
|
156
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
157
|
-
removeAuthStateDidChangeListener:[authStateHandlers valueForKey:firebaseApp.name]];
|
|
158
|
-
[authStateHandlers removeObjectForKey:firebaseApp.name];
|
|
159
|
-
}
|
|
57
|
+
[RNFBAuthHelper removeAuthStateListener:appName];
|
|
160
58
|
}
|
|
161
59
|
|
|
162
60
|
- (void)addIdTokenListener:(NSString *)appName {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (![idTokenHandlers valueForKey:firebaseApp.name]) {
|
|
166
|
-
FIRIDTokenDidChangeListenerHandle newListenerHandle = [[FIRAuth authWithApp:firebaseApp]
|
|
167
|
-
addIDTokenDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) {
|
|
168
|
-
if (user != nil) {
|
|
169
|
-
[RNFBSharedUtils sendJSEventForApp:firebaseApp
|
|
170
|
-
name:AUTH_ID_TOKEN_CHANGED_EVENT
|
|
171
|
-
body:@{keyUser : [self firebaseUserToDict:user]}];
|
|
172
|
-
} else {
|
|
173
|
-
[RNFBSharedUtils sendJSEventForApp:firebaseApp
|
|
174
|
-
name:AUTH_ID_TOKEN_CHANGED_EVENT
|
|
175
|
-
body:@{}];
|
|
176
|
-
}
|
|
177
|
-
}];
|
|
178
|
-
idTokenHandlers[firebaseApp.name] = newListenerHandle;
|
|
179
|
-
}
|
|
61
|
+
[RNFBAuthHelper addIdTokenListener:appName];
|
|
180
62
|
}
|
|
181
63
|
|
|
182
64
|
- (void)removeIdTokenListener:(NSString *)appName {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if ([idTokenHandlers valueForKey:firebaseApp.name]) {
|
|
186
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
187
|
-
removeIDTokenDidChangeListener:[idTokenHandlers valueForKey:firebaseApp.name]];
|
|
188
|
-
[idTokenHandlers removeObjectForKey:firebaseApp.name];
|
|
189
|
-
}
|
|
65
|
+
[RNFBAuthHelper removeIdTokenListener:appName];
|
|
190
66
|
}
|
|
191
67
|
|
|
192
68
|
- (void)configureAuthDomain:(NSString *)appName {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
NSString *authDomain = [RNFBAppModule getCustomDomain:firebaseApp.name];
|
|
196
|
-
DLog(@"RNFBAuth app: %@ customAuthDomain: %@", firebaseApp.name, authDomain);
|
|
197
|
-
if (authDomain != nil) {
|
|
198
|
-
[FIRAuth authWithApp:firebaseApp].customAuthDomain = authDomain;
|
|
199
|
-
}
|
|
69
|
+
[RNFBAuthHelper configureAuthDomain:appName];
|
|
200
70
|
}
|
|
201
71
|
|
|
202
72
|
- (void)getCustomAuthDomain:(NSString *)appName
|
|
203
73
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
204
74
|
reject:(RCTPromiseRejectBlock)reject {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
resolve([FIRAuth authWithApp:firebaseApp].customAuthDomain);
|
|
75
|
+
[RNFBAuthHelper getCustomAuthDomain:appName resolve:resolve reject:reject];
|
|
208
76
|
}
|
|
209
77
|
|
|
210
78
|
- (void)setAppVerificationDisabledForTesting:(NSString *)appName
|
|
211
79
|
disabled:(BOOL)disabled
|
|
212
80
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
213
81
|
reject:(RCTPromiseRejectBlock)reject {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
82
|
+
[RNFBAuthHelper setAppVerificationDisabledForTesting:appName
|
|
83
|
+
disabled:disabled
|
|
84
|
+
resolve:resolve
|
|
85
|
+
reject:reject];
|
|
218
86
|
}
|
|
219
87
|
|
|
220
88
|
- (void)forceRecaptchaFlowForTesting:(NSString *)appName
|
|
@@ -236,53 +104,22 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
236
104
|
userAccessGroup:(NSString *)userAccessGroup
|
|
237
105
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
238
106
|
reject:(RCTPromiseRejectBlock)reject {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (!error) {
|
|
245
|
-
[self promiseNoUser:resolve rejecter:reject isError:NO];
|
|
246
|
-
} else {
|
|
247
|
-
[self promiseRejectAuthException:reject error:error];
|
|
248
|
-
}
|
|
249
|
-
return;
|
|
107
|
+
[RNFBAuthHelper useUserAccessGroup:appName
|
|
108
|
+
userAccessGroup:userAccessGroup
|
|
109
|
+
resolve:resolve
|
|
110
|
+
reject:reject];
|
|
250
111
|
}
|
|
251
112
|
|
|
252
113
|
- (void)signOut:(NSString *)appName
|
|
253
114
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
254
115
|
reject:(RCTPromiseRejectBlock)reject {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
258
|
-
|
|
259
|
-
if (user) {
|
|
260
|
-
NSError *error;
|
|
261
|
-
[[FIRAuth authWithApp:firebaseApp] signOut:&error];
|
|
262
|
-
if (!error) {
|
|
263
|
-
[self promiseNoUser:resolve rejecter:reject isError:NO];
|
|
264
|
-
} else {
|
|
265
|
-
[self promiseRejectAuthException:reject error:error];
|
|
266
|
-
}
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
116
|
+
[RNFBAuthHelper signOut:appName resolve:resolve reject:reject];
|
|
271
117
|
}
|
|
272
118
|
|
|
273
119
|
- (void)signInAnonymously:(NSString *)appName
|
|
274
120
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
275
121
|
reject:(RCTPromiseRejectBlock)reject {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
279
|
-
signInAnonymouslyWithCompletion:^(FIRAuthDataResult *authResult, NSError *error) {
|
|
280
|
-
if (error) {
|
|
281
|
-
[self promiseRejectAuthException:reject error:error];
|
|
282
|
-
} else {
|
|
283
|
-
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
|
284
|
-
}
|
|
285
|
-
}];
|
|
122
|
+
[RNFBAuthHelper signInAnonymously:appName resolve:resolve reject:reject];
|
|
286
123
|
}
|
|
287
124
|
|
|
288
125
|
- (void)signInWithEmailAndPassword:(NSString *)appName
|
|
@@ -290,25 +127,15 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
290
127
|
password:(NSString *)password
|
|
291
128
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
292
129
|
reject:(RCTPromiseRejectBlock)reject {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
completion:^(FIRAuthDataResult *authResult, NSError *error) {
|
|
299
|
-
if (error) {
|
|
300
|
-
[self promiseRejectAuthException:reject error:error];
|
|
301
|
-
} else {
|
|
302
|
-
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
|
303
|
-
}
|
|
304
|
-
}];
|
|
130
|
+
[RNFBAuthHelper signInWithEmailAndPassword:appName
|
|
131
|
+
email:email
|
|
132
|
+
password:password
|
|
133
|
+
resolve:resolve
|
|
134
|
+
reject:reject];
|
|
305
135
|
}
|
|
306
136
|
|
|
307
137
|
- (NSNumber *)isSignInWithEmailLink:(NSString *)appName emailLink:(NSString *)emailLink {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return
|
|
311
|
-
@([RCTConvert BOOL:@([[FIRAuth authWithApp:firebaseApp] isSignInWithEmailLink:emailLink])]);
|
|
138
|
+
return [RNFBAuthHelper isSignInWithEmailLink:appName emailLink:emailLink];
|
|
312
139
|
}
|
|
313
140
|
|
|
314
141
|
- (void)signInWithEmailLink:(NSString *)appName
|
|
@@ -316,18 +143,11 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
316
143
|
emailLink:(NSString *)emailLink
|
|
317
144
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
318
145
|
reject:(RCTPromiseRejectBlock)reject {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
completion:^(FIRAuthDataResult *authResult, NSError *error) {
|
|
325
|
-
if (error) {
|
|
326
|
-
[self promiseRejectAuthException:reject error:error];
|
|
327
|
-
} else {
|
|
328
|
-
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
|
329
|
-
}
|
|
330
|
-
}];
|
|
146
|
+
[RNFBAuthHelper signInWithEmailLink:appName
|
|
147
|
+
email:email
|
|
148
|
+
emailLink:emailLink
|
|
149
|
+
resolve:resolve
|
|
150
|
+
reject:reject];
|
|
331
151
|
}
|
|
332
152
|
|
|
333
153
|
- (void)createUserWithEmailAndPassword:(NSString *)appName
|
|
@@ -335,78 +155,33 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
335
155
|
password:(NSString *)password
|
|
336
156
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
337
157
|
reject:(RCTPromiseRejectBlock)reject {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
completion:^(FIRAuthDataResult *authResult, NSError *error) {
|
|
344
|
-
if (error) {
|
|
345
|
-
[self promiseRejectAuthException:reject error:error];
|
|
346
|
-
} else {
|
|
347
|
-
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
|
348
|
-
}
|
|
349
|
-
}];
|
|
158
|
+
[RNFBAuthHelper createUserWithEmailAndPassword:appName
|
|
159
|
+
email:email
|
|
160
|
+
password:password
|
|
161
|
+
resolve:resolve
|
|
162
|
+
reject:reject];
|
|
350
163
|
}
|
|
351
164
|
|
|
352
165
|
- (void)deleteUser:(NSString *)appName
|
|
353
166
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
354
167
|
reject:(RCTPromiseRejectBlock)reject {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
358
|
-
|
|
359
|
-
if (user) {
|
|
360
|
-
[user deleteWithCompletion:^(NSError *_Nullable error) {
|
|
361
|
-
if (error) {
|
|
362
|
-
[self promiseRejectAuthException:reject error:error];
|
|
363
|
-
} else {
|
|
364
|
-
[self promiseNoUser:resolve rejecter:reject isError:NO];
|
|
365
|
-
}
|
|
366
|
-
}];
|
|
367
|
-
} else {
|
|
368
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
369
|
-
}
|
|
168
|
+
[RNFBAuthHelper deleteUser:appName resolve:resolve reject:reject];
|
|
370
169
|
}
|
|
371
170
|
|
|
372
171
|
- (void)reload:(NSString *)appName
|
|
373
172
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
374
173
|
reject:(RCTPromiseRejectBlock)reject {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
378
|
-
if (user) {
|
|
379
|
-
[self reloadAndReturnUser:user resolver:resolve rejecter:reject firebaseApp:firebaseApp];
|
|
380
|
-
} else {
|
|
381
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
382
|
-
}
|
|
174
|
+
[RNFBAuthHelper reload:appName resolve:resolve reject:reject];
|
|
383
175
|
}
|
|
384
176
|
|
|
385
177
|
- (void)sendEmailVerification:(NSString *)appName
|
|
386
178
|
actionCodeSettings:(NSDictionary *)actionCodeSettings
|
|
387
179
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
388
180
|
reject:(RCTPromiseRejectBlock)reject {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
id handler = ^(NSError *_Nullable error) {
|
|
394
|
-
if (error) {
|
|
395
|
-
[self promiseRejectAuthException:reject error:error];
|
|
396
|
-
} else {
|
|
397
|
-
FIRUser *userAfterUpdate = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
398
|
-
[self promiseWithUser:resolve rejecter:reject user:userAfterUpdate];
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
if (actionCodeSettings) {
|
|
402
|
-
FIRActionCodeSettings *settings = [self buildActionCodeSettings:actionCodeSettings];
|
|
403
|
-
[user sendEmailVerificationWithActionCodeSettings:settings completion:handler];
|
|
404
|
-
} else {
|
|
405
|
-
[user sendEmailVerificationWithCompletion:handler];
|
|
406
|
-
}
|
|
407
|
-
} else {
|
|
408
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
409
|
-
}
|
|
181
|
+
[RNFBAuthHelper sendEmailVerification:appName
|
|
182
|
+
actionCodeSettings:actionCodeSettings
|
|
183
|
+
resolve:resolve
|
|
184
|
+
reject:reject];
|
|
410
185
|
}
|
|
411
186
|
|
|
412
187
|
- (void)verifyBeforeUpdateEmail:(NSString *)appName
|
|
@@ -414,77 +189,25 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
414
189
|
actionCodeSettings:(NSDictionary *)actionCodeSettings
|
|
415
190
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
416
191
|
reject:(RCTPromiseRejectBlock)reject {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (error) {
|
|
423
|
-
[self promiseRejectAuthException:reject error:error];
|
|
424
|
-
} else {
|
|
425
|
-
FIRUser *userAfterUpdate = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
426
|
-
[self promiseWithUser:resolve rejecter:reject user:userAfterUpdate];
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
if (actionCodeSettings) {
|
|
430
|
-
FIRActionCodeSettings *settings = [self buildActionCodeSettings:actionCodeSettings];
|
|
431
|
-
[user sendEmailVerificationBeforeUpdatingEmail:email
|
|
432
|
-
actionCodeSettings:settings
|
|
433
|
-
completion:handler];
|
|
434
|
-
} else {
|
|
435
|
-
[user sendEmailVerificationBeforeUpdatingEmail:email completion:handler];
|
|
436
|
-
}
|
|
437
|
-
} else {
|
|
438
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
439
|
-
}
|
|
192
|
+
[RNFBAuthHelper verifyBeforeUpdateEmail:appName
|
|
193
|
+
email:email
|
|
194
|
+
actionCodeSettings:actionCodeSettings
|
|
195
|
+
resolve:resolve
|
|
196
|
+
reject:reject];
|
|
440
197
|
}
|
|
441
198
|
|
|
442
199
|
- (void)updateEmail:(NSString *)appName
|
|
443
200
|
email:(NSString *)email
|
|
444
201
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
445
202
|
reject:(RCTPromiseRejectBlock)reject {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
449
|
-
|
|
450
|
-
if (user) {
|
|
451
|
-
[user updateEmail:email
|
|
452
|
-
completion:^(NSError *_Nullable error) {
|
|
453
|
-
if (error) {
|
|
454
|
-
[self promiseRejectAuthException:reject error:error];
|
|
455
|
-
} else {
|
|
456
|
-
[self reloadAndReturnUser:user
|
|
457
|
-
resolver:resolve
|
|
458
|
-
rejecter:reject
|
|
459
|
-
firebaseApp:firebaseApp];
|
|
460
|
-
}
|
|
461
|
-
}];
|
|
462
|
-
} else {
|
|
463
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
464
|
-
}
|
|
203
|
+
[RNFBAuthHelper updateEmail:appName email:email resolve:resolve reject:reject];
|
|
465
204
|
}
|
|
466
205
|
|
|
467
206
|
- (void)updatePassword:(NSString *)appName
|
|
468
207
|
password:(NSString *)password
|
|
469
208
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
470
209
|
reject:(RCTPromiseRejectBlock)reject {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
474
|
-
|
|
475
|
-
if (user) {
|
|
476
|
-
[user updatePassword:password
|
|
477
|
-
completion:^(NSError *_Nullable error) {
|
|
478
|
-
if (error) {
|
|
479
|
-
[self promiseRejectAuthException:reject error:error];
|
|
480
|
-
} else {
|
|
481
|
-
FIRUser *userAfterUpdate = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
482
|
-
[self promiseWithUser:resolve rejecter:reject user:userAfterUpdate];
|
|
483
|
-
}
|
|
484
|
-
}];
|
|
485
|
-
} else {
|
|
486
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
487
|
-
}
|
|
210
|
+
[RNFBAuthHelper updatePassword:appName password:password resolve:resolve reject:reject];
|
|
488
211
|
}
|
|
489
212
|
|
|
490
213
|
#if TARGET_OS_IOS
|
|
@@ -494,40 +217,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
494
217
|
authSecret:(NSString *)authSecret
|
|
495
218
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
496
219
|
reject:(RCTPromiseRejectBlock)reject {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
(FIRPhoneAuthCredential *)[self getCredentialForProvider:provider
|
|
504
|
-
token:authToken
|
|
505
|
-
secret:authSecret
|
|
506
|
-
firebaseApp:firebaseApp];
|
|
507
|
-
|
|
508
|
-
if (credential == nil) {
|
|
509
|
-
[RNFBSharedUtils
|
|
510
|
-
rejectPromiseWithUserInfo:reject
|
|
511
|
-
userInfo:(NSMutableDictionary *)@{
|
|
512
|
-
@"code" : @"invalid-credential",
|
|
513
|
-
@"message" : @"The supplied auth credential is malformed, has expired "
|
|
514
|
-
@"or is not currently supported.",
|
|
515
|
-
}];
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
[user updatePhoneNumberCredential:credential
|
|
519
|
-
completion:^(NSError *_Nullable error) {
|
|
520
|
-
if (error) {
|
|
521
|
-
[self promiseRejectAuthException:reject error:error];
|
|
522
|
-
} else {
|
|
523
|
-
FIRUser *userAfterUpdate =
|
|
524
|
-
[FIRAuth authWithApp:firebaseApp].currentUser;
|
|
525
|
-
[self promiseWithUser:resolve rejecter:reject user:userAfterUpdate];
|
|
526
|
-
}
|
|
527
|
-
}];
|
|
528
|
-
} else {
|
|
529
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
530
|
-
}
|
|
220
|
+
[RNFBAuthHelper updatePhoneNumber:appName
|
|
221
|
+
provider:provider
|
|
222
|
+
authToken:authToken
|
|
223
|
+
authSecret:authSecret
|
|
224
|
+
resolve:resolve
|
|
225
|
+
reject:reject];
|
|
531
226
|
}
|
|
532
227
|
#endif
|
|
533
228
|
|
|
@@ -535,200 +230,44 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
535
230
|
props:(NSDictionary *)props
|
|
536
231
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
537
232
|
reject:(RCTPromiseRejectBlock)reject {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
541
|
-
|
|
542
|
-
if (user) {
|
|
543
|
-
FIRUserProfileChangeRequest *changeRequest = [user profileChangeRequest];
|
|
544
|
-
NSMutableArray *allKeys = [[props allKeys] mutableCopy];
|
|
545
|
-
|
|
546
|
-
for (NSString *key in allKeys) {
|
|
547
|
-
@try {
|
|
548
|
-
if ([key isEqualToString:keyPhotoUrl]) {
|
|
549
|
-
NSURL *url = [NSURL URLWithString:[props valueForKey:key]];
|
|
550
|
-
[changeRequest setValue:url forKey:key];
|
|
551
|
-
} else {
|
|
552
|
-
[changeRequest setValue:props[key] forKey:key];
|
|
553
|
-
}
|
|
554
|
-
} @catch (NSException *exception) {
|
|
555
|
-
DLog(@"Exception occurred while configuring: %@", exception);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
[changeRequest commitChangesWithCompletion:^(NSError *_Nullable error) {
|
|
560
|
-
if (error) {
|
|
561
|
-
[self promiseRejectAuthException:reject error:error];
|
|
562
|
-
} else {
|
|
563
|
-
[self reloadAndReturnUser:user resolver:resolve rejecter:reject firebaseApp:firebaseApp];
|
|
564
|
-
}
|
|
565
|
-
}];
|
|
566
|
-
} else {
|
|
567
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
568
|
-
}
|
|
233
|
+
[RNFBAuthHelper updateProfile:appName props:props resolve:resolve reject:reject];
|
|
569
234
|
}
|
|
570
235
|
|
|
571
236
|
- (void)getIdToken:(NSString *)appName
|
|
572
237
|
forceRefresh:(BOOL)forceRefresh
|
|
573
238
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
574
239
|
reject:(RCTPromiseRejectBlock)reject {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
578
|
-
|
|
579
|
-
if (user) {
|
|
580
|
-
[user getIDTokenForcingRefresh:(BOOL)forceRefresh
|
|
581
|
-
completion:^(NSString *token, NSError *_Nullable error) {
|
|
582
|
-
if (error) {
|
|
583
|
-
[self promiseRejectAuthException:reject error:error];
|
|
584
|
-
} else {
|
|
585
|
-
resolve(token);
|
|
586
|
-
}
|
|
587
|
-
}];
|
|
588
|
-
} else {
|
|
589
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
590
|
-
}
|
|
240
|
+
[RNFBAuthHelper getIdToken:appName forceRefresh:forceRefresh resolve:resolve reject:reject];
|
|
591
241
|
}
|
|
592
242
|
|
|
593
243
|
- (void)getIdTokenResult:(NSString *)appName
|
|
594
244
|
forceRefresh:(BOOL)forceRefresh
|
|
595
245
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
596
246
|
reject:(RCTPromiseRejectBlock)reject {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
600
|
-
|
|
601
|
-
if (user) {
|
|
602
|
-
[user
|
|
603
|
-
getIDTokenResultForcingRefresh:(BOOL)forceRefresh
|
|
604
|
-
completion:^(FIRAuthTokenResult *_Nullable tokenResult,
|
|
605
|
-
NSError *_Nullable error) {
|
|
606
|
-
if (error) {
|
|
607
|
-
[self promiseRejectAuthException:reject error:error];
|
|
608
|
-
} else {
|
|
609
|
-
NSMutableDictionary *tokenResultDict =
|
|
610
|
-
[NSMutableDictionary dictionary];
|
|
611
|
-
[tokenResultDict
|
|
612
|
-
setValue:[RNFBSharedUtils getISO8601String:tokenResult.authDate]
|
|
613
|
-
forKey:@"authTime"];
|
|
614
|
-
[tokenResultDict
|
|
615
|
-
setValue:[RNFBSharedUtils
|
|
616
|
-
getISO8601String:tokenResult.issuedAtDate]
|
|
617
|
-
forKey:@"issuedAtTime"];
|
|
618
|
-
[tokenResultDict
|
|
619
|
-
setValue:[RNFBSharedUtils
|
|
620
|
-
getISO8601String:tokenResult.expirationDate]
|
|
621
|
-
forKey:@"expirationTime"];
|
|
622
|
-
|
|
623
|
-
[tokenResultDict setValue:tokenResult.token forKey:@"token"];
|
|
624
|
-
[tokenResultDict setValue:tokenResult.claims forKey:@"claims"];
|
|
625
|
-
|
|
626
|
-
NSString *provider = tokenResult.signInProvider;
|
|
627
|
-
if (!provider) {
|
|
628
|
-
provider = tokenResult.claims[@"firebase"][@"sign_in_provider"];
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
[tokenResultDict setValue:provider forKey:@"signInProvider"];
|
|
632
|
-
resolve(tokenResultDict);
|
|
633
|
-
}
|
|
634
|
-
}];
|
|
635
|
-
} else {
|
|
636
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
637
|
-
}
|
|
247
|
+
[RNFBAuthHelper getIdTokenResult:appName forceRefresh:forceRefresh resolve:resolve reject:reject];
|
|
638
248
|
}
|
|
639
249
|
|
|
640
250
|
- (void)signInWithCredential:(NSString *)appName
|
|
641
251
|
provider:(NSString *)provider
|
|
642
252
|
authToken:(NSString *)authToken
|
|
643
253
|
authSecret:(NSString *)authSecret
|
|
254
|
+
fullName:(NSDictionary *)fullName
|
|
644
255
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
645
256
|
reject:(RCTPromiseRejectBlock)reject {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
654
|
-
userInfo:(NSMutableDictionary *)@{
|
|
655
|
-
@"code" : @"invalid-credential",
|
|
656
|
-
@"message" : @"The supplied auth credential is malformed, "
|
|
657
|
-
@"has expired or is not currently supported.",
|
|
658
|
-
}];
|
|
659
|
-
}
|
|
660
|
-
DLog(@"using app SignInWithCredential: %@", firebaseApp.name);
|
|
661
|
-
|
|
662
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
663
|
-
signInWithCredential:credential
|
|
664
|
-
completion:^(FIRAuthDataResult *authResult, NSError *error) {
|
|
665
|
-
if (error) {
|
|
666
|
-
[self promiseRejectAuthException:reject error:error];
|
|
667
|
-
} else {
|
|
668
|
-
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
|
669
|
-
}
|
|
670
|
-
}];
|
|
257
|
+
[RNFBAuthHelper signInWithCredential:appName
|
|
258
|
+
provider:provider
|
|
259
|
+
authToken:authToken
|
|
260
|
+
authSecret:authSecret
|
|
261
|
+
fullName:fullName
|
|
262
|
+
resolve:resolve
|
|
263
|
+
reject:reject];
|
|
671
264
|
}
|
|
672
265
|
|
|
673
266
|
- (void)signInWithProvider:(NSString *)appName
|
|
674
267
|
provider:(NSDictionary *)provider
|
|
675
268
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
676
269
|
reject:(RCTPromiseRejectBlock)reject {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
NSString *providerId = provider[@"providerId"];
|
|
680
|
-
if (providerId == nil) {
|
|
681
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
682
|
-
userInfo:(NSMutableDictionary *)@{
|
|
683
|
-
@"code" : @"invalid-credential",
|
|
684
|
-
@"message" : @"The supplied auth credential is malformed, "
|
|
685
|
-
@"has expired or is not currently supported.",
|
|
686
|
-
}];
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
__block FIROAuthProvider *builder =
|
|
690
|
-
[FIROAuthProvider providerWithProviderID:providerId auth:[FIRAuth authWithApp:firebaseApp]];
|
|
691
|
-
// Add scopes if present
|
|
692
|
-
if (provider[@"scopes"]) {
|
|
693
|
-
[builder setScopes:provider[@"scopes"]];
|
|
694
|
-
}
|
|
695
|
-
// Add custom parameters if present
|
|
696
|
-
if (provider[@"customParameters"]) {
|
|
697
|
-
[builder setCustomParameters:provider[@"customParameters"]];
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
#if TARGET_OS_IOS
|
|
701
|
-
[builder getCredentialWithUIDelegate:nil
|
|
702
|
-
completion:^(FIRAuthCredential *_Nullable credential,
|
|
703
|
-
NSError *_Nullable error) {
|
|
704
|
-
if (error) {
|
|
705
|
-
[self promiseRejectAuthException:reject error:error];
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
if (credential) {
|
|
709
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
710
|
-
signInWithCredential:credential
|
|
711
|
-
completion:^(FIRAuthDataResult *_Nullable authResult,
|
|
712
|
-
NSError *_Nullable error) {
|
|
713
|
-
if (error) {
|
|
714
|
-
[self promiseRejectAuthException:reject
|
|
715
|
-
error:error];
|
|
716
|
-
return;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
// NOTE: This variable has NO PURPOSE AT ALL, it is
|
|
720
|
-
// only to keep a strong reference to the builder
|
|
721
|
-
// variable so it is not deallocated prematurely by
|
|
722
|
-
// ARC.
|
|
723
|
-
NSString *providerID = builder.providerID;
|
|
724
|
-
|
|
725
|
-
[self promiseWithAuthResult:resolve
|
|
726
|
-
rejecter:reject
|
|
727
|
-
authResult:authResult];
|
|
728
|
-
}];
|
|
729
|
-
}
|
|
730
|
-
}];
|
|
731
|
-
#endif
|
|
270
|
+
[RNFBAuthHelper signInWithProvider:appName provider:provider resolve:resolve reject:reject];
|
|
732
271
|
}
|
|
733
272
|
|
|
734
273
|
- (void)confirmPasswordReset:(NSString *)appName
|
|
@@ -736,111 +275,35 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
736
275
|
newPassword:(NSString *)newPassword
|
|
737
276
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
738
277
|
reject:(RCTPromiseRejectBlock)reject {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
completion:^(NSError *_Nullable error) {
|
|
745
|
-
if (error) {
|
|
746
|
-
[self promiseRejectAuthException:reject error:error];
|
|
747
|
-
} else {
|
|
748
|
-
[self promiseNoUser:resolve rejecter:reject isError:NO];
|
|
749
|
-
}
|
|
750
|
-
}];
|
|
278
|
+
[RNFBAuthHelper confirmPasswordReset:appName
|
|
279
|
+
code:code
|
|
280
|
+
newPassword:newPassword
|
|
281
|
+
resolve:resolve
|
|
282
|
+
reject:reject];
|
|
751
283
|
}
|
|
752
284
|
|
|
753
285
|
- (void)applyActionCode:(NSString *)appName
|
|
754
286
|
code:(NSString *)code
|
|
755
287
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
756
288
|
reject:(RCTPromiseRejectBlock)reject {
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
760
|
-
applyActionCode:code
|
|
761
|
-
completion:^(NSError *_Nullable error) {
|
|
762
|
-
if (error) {
|
|
763
|
-
[self promiseRejectAuthException:reject error:error];
|
|
764
|
-
} else {
|
|
765
|
-
[self promiseWithUser:resolve
|
|
766
|
-
rejecter:reject
|
|
767
|
-
user:[FIRAuth authWithApp:firebaseApp].currentUser];
|
|
768
|
-
}
|
|
769
|
-
}];
|
|
289
|
+
[RNFBAuthHelper applyActionCode:appName code:code resolve:resolve reject:reject];
|
|
770
290
|
}
|
|
771
291
|
|
|
772
292
|
- (void)checkActionCode:(NSString *)appName
|
|
773
293
|
code:(NSString *)code
|
|
774
294
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
775
295
|
reject:(RCTPromiseRejectBlock)reject {
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
779
|
-
checkActionCode:code
|
|
780
|
-
completion:^(FIRActionCodeInfo *_Nullable info, NSError *_Nullable error) {
|
|
781
|
-
if (error) {
|
|
782
|
-
[self promiseRejectAuthException:reject error:error];
|
|
783
|
-
} else {
|
|
784
|
-
NSString *actionType = @"ERROR";
|
|
785
|
-
switch (info.operation) {
|
|
786
|
-
case FIRActionCodeOperationPasswordReset:
|
|
787
|
-
actionType = @"PASSWORD_RESET";
|
|
788
|
-
break;
|
|
789
|
-
case FIRActionCodeOperationVerifyEmail:
|
|
790
|
-
actionType = @"VERIFY_EMAIL";
|
|
791
|
-
break;
|
|
792
|
-
case FIRActionCodeOperationUnknown:
|
|
793
|
-
actionType = @"UNKNOWN";
|
|
794
|
-
break;
|
|
795
|
-
case FIRActionCodeOperationRecoverEmail:
|
|
796
|
-
actionType = @"RECOVER_EMAIL";
|
|
797
|
-
break;
|
|
798
|
-
case FIRActionCodeOperationEmailLink:
|
|
799
|
-
actionType = @"EMAIL_SIGNIN";
|
|
800
|
-
break;
|
|
801
|
-
case FIRActionCodeOperationVerifyAndChangeEmail:
|
|
802
|
-
case FIRActionCodeOperationRevertSecondFactorAddition:
|
|
803
|
-
default:
|
|
804
|
-
actionType = @"ERROR";
|
|
805
|
-
break;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
|
809
|
-
|
|
810
|
-
if (info.email != nil) {
|
|
811
|
-
[data setValue:info.email forKey:keyEmail];
|
|
812
|
-
} else {
|
|
813
|
-
[data setValue:[NSNull null] forKey:keyEmail];
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
if (info.previousEmail != nil) {
|
|
817
|
-
[data setValue:info.previousEmail forKey:@"fromEmail"];
|
|
818
|
-
} else {
|
|
819
|
-
[data setValue:[NSNull null] forKey:@"fromEmail"];
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
NSDictionary *result = @{@"data" : data, @"operation" : actionType};
|
|
823
|
-
|
|
824
|
-
resolve(result);
|
|
825
|
-
}
|
|
826
|
-
}];
|
|
296
|
+
[RNFBAuthHelper checkActionCode:appName code:code resolve:resolve reject:reject];
|
|
827
297
|
}
|
|
828
298
|
|
|
829
299
|
- (void)revokeToken:(NSString *)appName
|
|
830
300
|
authorizationCode:(NSString *)authorizationCode
|
|
831
301
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
832
302
|
reject:(RCTPromiseRejectBlock)reject {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
completion:^(NSError *_Nullable error) {
|
|
838
|
-
if (error) {
|
|
839
|
-
[self promiseRejectAuthException:reject error:error];
|
|
840
|
-
} else {
|
|
841
|
-
[self promiseNoUser:resolve rejecter:reject isError:NO];
|
|
842
|
-
}
|
|
843
|
-
}];
|
|
303
|
+
[RNFBAuthHelper revokeToken:appName
|
|
304
|
+
authorizationCode:authorizationCode
|
|
305
|
+
resolve:resolve
|
|
306
|
+
reject:reject];
|
|
844
307
|
}
|
|
845
308
|
|
|
846
309
|
- (void)sendPasswordResetEmail:(NSString *)appName
|
|
@@ -848,24 +311,11 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
848
311
|
actionCodeSettings:(NSDictionary *)actionCodeSettings
|
|
849
312
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
850
313
|
reject:(RCTPromiseRejectBlock)reject {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
} else {
|
|
857
|
-
[self promiseNoUser:resolve rejecter:reject isError:NO];
|
|
858
|
-
}
|
|
859
|
-
};
|
|
860
|
-
|
|
861
|
-
if (actionCodeSettings) {
|
|
862
|
-
FIRActionCodeSettings *settings = [self buildActionCodeSettings:actionCodeSettings];
|
|
863
|
-
[[FIRAuth authWithApp:firebaseApp] sendPasswordResetWithEmail:email
|
|
864
|
-
actionCodeSettings:settings
|
|
865
|
-
completion:handler];
|
|
866
|
-
} else {
|
|
867
|
-
[[FIRAuth authWithApp:firebaseApp] sendPasswordResetWithEmail:email completion:handler];
|
|
868
|
-
}
|
|
314
|
+
[RNFBAuthHelper sendPasswordResetEmail:appName
|
|
315
|
+
email:email
|
|
316
|
+
actionCodeSettings:actionCodeSettings
|
|
317
|
+
resolve:resolve
|
|
318
|
+
reject:reject];
|
|
869
319
|
}
|
|
870
320
|
|
|
871
321
|
- (void)sendSignInLinkToEmail:(NSString *)appName
|
|
@@ -873,37 +323,18 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
873
323
|
actionCodeSettings:(NSDictionary *)actionCodeSettings
|
|
874
324
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
875
325
|
reject:(RCTPromiseRejectBlock)reject {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
} else {
|
|
882
|
-
[self promiseNoUser:resolve rejecter:reject isError:NO];
|
|
883
|
-
}
|
|
884
|
-
};
|
|
885
|
-
|
|
886
|
-
FIRActionCodeSettings *settings = [self buildActionCodeSettings:actionCodeSettings];
|
|
887
|
-
[[FIRAuth authWithApp:firebaseApp] sendSignInLinkToEmail:email
|
|
888
|
-
actionCodeSettings:settings
|
|
889
|
-
completion:handler];
|
|
326
|
+
[RNFBAuthHelper sendSignInLinkToEmail:appName
|
|
327
|
+
email:email
|
|
328
|
+
actionCodeSettings:actionCodeSettings
|
|
329
|
+
resolve:resolve
|
|
330
|
+
reject:reject];
|
|
890
331
|
}
|
|
891
332
|
|
|
892
333
|
- (void)signInWithCustomToken:(NSString *)appName
|
|
893
|
-
|
|
334
|
+
token:(NSString *)token
|
|
894
335
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
895
336
|
reject:(RCTPromiseRejectBlock)reject {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
899
|
-
signInWithCustomToken:customToken
|
|
900
|
-
completion:^(FIRAuthDataResult *authResult, NSError *error) {
|
|
901
|
-
if (error) {
|
|
902
|
-
[self promiseRejectAuthException:reject error:error];
|
|
903
|
-
} else {
|
|
904
|
-
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
|
905
|
-
}
|
|
906
|
-
}];
|
|
337
|
+
[RNFBAuthHelper signInWithCustomToken:appName customToken:token resolve:resolve reject:reject];
|
|
907
338
|
}
|
|
908
339
|
|
|
909
340
|
#if TARGET_OS_IOS
|
|
@@ -912,69 +343,23 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
912
343
|
forceResend:(BOOL)forceResend
|
|
913
344
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
914
345
|
reject:(RCTPromiseRejectBlock)reject {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
[[FIRPhoneAuthProvider providerWithAuth:[FIRAuth authWithApp:firebaseApp]]
|
|
922
|
-
verifyPhoneNumber:phoneNumber
|
|
923
|
-
UIDelegate:nil
|
|
924
|
-
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
|
|
925
|
-
if (error) {
|
|
926
|
-
[self promiseRejectAuthException:reject error:error];
|
|
927
|
-
} else {
|
|
928
|
-
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
929
|
-
[defaults setObject:verificationID forKey:@"authVerificationID"];
|
|
930
|
-
resolve(@{@"verificationId" : verificationID});
|
|
931
|
-
}
|
|
932
|
-
}];
|
|
346
|
+
[RNFBAuthHelper signInWithPhoneNumber:appName
|
|
347
|
+
phoneNumber:phoneNumber
|
|
348
|
+
forceResend:forceResend
|
|
349
|
+
resolve:resolve
|
|
350
|
+
reject:reject];
|
|
933
351
|
}
|
|
352
|
+
|
|
934
353
|
- (void)verifyPhoneNumberWithMultiFactorInfo:(NSString *)appName
|
|
935
354
|
hintUid:(NSString *)hintUid
|
|
936
355
|
sessionKey:(NSString *)sessionKey
|
|
937
356
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
938
357
|
reject:(RCTPromiseRejectBlock)reject {
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
userInfo:(NSMutableDictionary *)@{
|
|
945
|
-
@"code" : @"invalid-multi-factor-session",
|
|
946
|
-
@"message" : @"No resolver for session found. Is the session id correct?"
|
|
947
|
-
}];
|
|
948
|
-
return;
|
|
949
|
-
}
|
|
950
|
-
FIRMultiFactorSession *session = cachedResolver[sessionKey].session;
|
|
951
|
-
NSPredicate *findByUid = [NSPredicate predicateWithFormat:@"UID == %@", hintUid];
|
|
952
|
-
FIRMultiFactorInfo *_Nullable hint =
|
|
953
|
-
[[cachedResolver[sessionKey].hints filteredArrayUsingPredicate:findByUid] firstObject];
|
|
954
|
-
if (hint == nil) {
|
|
955
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
956
|
-
userInfo:(NSMutableDictionary *)@{
|
|
957
|
-
@"code" : @"multi-factor-info-not-found",
|
|
958
|
-
@"message" : @"The user does not have a second factor "
|
|
959
|
-
@"matching the identifier provided."
|
|
960
|
-
}];
|
|
961
|
-
return;
|
|
962
|
-
}
|
|
963
|
-
DLog(@"using instance verifyPhoneNumberWithMultiFactorInfo: %@", firebaseApp.name);
|
|
964
|
-
|
|
965
|
-
[[FIRPhoneAuthProvider providerWithAuth:[FIRAuth authWithApp:firebaseApp]]
|
|
966
|
-
verifyPhoneNumberWithMultiFactorInfo:hint
|
|
967
|
-
UIDelegate:nil
|
|
968
|
-
multiFactorSession:session
|
|
969
|
-
completion:^(NSString *_Nullable verificationID,
|
|
970
|
-
NSError *_Nullable error) {
|
|
971
|
-
if (error) {
|
|
972
|
-
[self promiseRejectAuthException:reject error:error];
|
|
973
|
-
} else {
|
|
974
|
-
DLog(@"verificationID: %@", verificationID)
|
|
975
|
-
resolve(verificationID);
|
|
976
|
-
}
|
|
977
|
-
}];
|
|
358
|
+
[RNFBAuthHelper verifyPhoneNumberWithMultiFactorInfo:appName
|
|
359
|
+
hintUid:hintUid
|
|
360
|
+
sessionKey:sessionKey
|
|
361
|
+
resolve:resolve
|
|
362
|
+
reject:reject];
|
|
978
363
|
}
|
|
979
364
|
|
|
980
365
|
- (void)verifyPhoneNumberForMultiFactor:(NSString *)appName
|
|
@@ -982,32 +367,11 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
982
367
|
sessionKey:(NSString *)sessionKey
|
|
983
368
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
984
369
|
reject:(RCTPromiseRejectBlock)reject {
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
FIRMultiFactorSession *session = cachedSessions[sessionKey];
|
|
991
|
-
if (session == nil) {
|
|
992
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
993
|
-
userInfo:(NSMutableDictionary *)@{
|
|
994
|
-
@"code" : @"invalid-multi-factor-session",
|
|
995
|
-
@"message" : @"can't find session for provided key"
|
|
996
|
-
}];
|
|
997
|
-
return;
|
|
998
|
-
}
|
|
999
|
-
[[FIRPhoneAuthProvider providerWithAuth:[FIRAuth authWithApp:firebaseApp]]
|
|
1000
|
-
verifyPhoneNumber:phoneNumber
|
|
1001
|
-
UIDelegate:nil
|
|
1002
|
-
multiFactorSession:session
|
|
1003
|
-
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
|
|
1004
|
-
if (error != nil) {
|
|
1005
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1006
|
-
return;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
resolve(verificationID);
|
|
1010
|
-
}];
|
|
370
|
+
[RNFBAuthHelper verifyPhoneNumberForMultiFactor:appName
|
|
371
|
+
phoneNumber:phoneNumber
|
|
372
|
+
sessionKey:sessionKey
|
|
373
|
+
resolve:resolve
|
|
374
|
+
reject:reject];
|
|
1011
375
|
}
|
|
1012
376
|
|
|
1013
377
|
- (void)resolveMultiFactorSignIn:(NSString *)appName
|
|
@@ -1016,31 +380,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
1016
380
|
verificationCode:(NSString *)verificationCode
|
|
1017
381
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1018
382
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
credentialWithVerificationID:verificationId
|
|
1026
|
-
verificationCode:verificationCode];
|
|
1027
|
-
DLog(@"credential: %@", credential);
|
|
1028
|
-
|
|
1029
|
-
FIRMultiFactorAssertion *assertion =
|
|
1030
|
-
[FIRPhoneMultiFactorGenerator assertionWithCredential:credential];
|
|
1031
|
-
|
|
1032
|
-
[cachedResolver[session] resolveSignInWithAssertion:assertion
|
|
1033
|
-
completion:^(FIRAuthDataResult *_Nullable authResult,
|
|
1034
|
-
NSError *_Nullable error) {
|
|
1035
|
-
DLog(@"authError: %@", error) if (error) {
|
|
1036
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1037
|
-
}
|
|
1038
|
-
else {
|
|
1039
|
-
[self promiseWithAuthResult:resolve
|
|
1040
|
-
rejecter:reject
|
|
1041
|
-
authResult:authResult];
|
|
1042
|
-
}
|
|
1043
|
-
}];
|
|
383
|
+
[RNFBAuthHelper resolveMultiFactorSignIn:appName
|
|
384
|
+
session:session
|
|
385
|
+
verificationId:verificationId
|
|
386
|
+
verificationCode:verificationCode
|
|
387
|
+
resolve:resolve
|
|
388
|
+
reject:reject];
|
|
1044
389
|
}
|
|
1045
390
|
|
|
1046
391
|
- (void)resolveTotpSignIn:(NSString *)appName
|
|
@@ -1049,125 +394,48 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
1049
394
|
oneTimePassword:(NSString *)oneTimePassword
|
|
1050
395
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1051
396
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
oneTimePassword:oneTimePassword];
|
|
1059
|
-
[cachedResolver[sessionKey] resolveSignInWithAssertion:assertion
|
|
1060
|
-
completion:^(FIRAuthDataResult *_Nullable authResult,
|
|
1061
|
-
NSError *_Nullable error) {
|
|
1062
|
-
DLog(@"authError: %@", error) if (error) {
|
|
1063
|
-
[self promiseRejectAuthException:reject
|
|
1064
|
-
error:error];
|
|
1065
|
-
}
|
|
1066
|
-
else {
|
|
1067
|
-
[self promiseWithAuthResult:resolve
|
|
1068
|
-
rejecter:reject
|
|
1069
|
-
authResult:authResult];
|
|
1070
|
-
}
|
|
1071
|
-
}];
|
|
397
|
+
[RNFBAuthHelper resolveTotpSignIn:appName
|
|
398
|
+
sessionKey:sessionKey
|
|
399
|
+
uid:uid
|
|
400
|
+
oneTimePassword:oneTimePassword
|
|
401
|
+
resolve:resolve
|
|
402
|
+
reject:reject];
|
|
1072
403
|
}
|
|
1073
404
|
|
|
1074
405
|
- (void)generateTotpSecret:(NSString *)appName
|
|
1075
406
|
sessionKey:(NSString *)sessionKey
|
|
1076
407
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1077
408
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
DLog(@"using instance resolve generateTotpSecret: %@", firebaseApp.name);
|
|
1081
|
-
|
|
1082
|
-
FIRMultiFactorSession *session = cachedSessions[sessionKey];
|
|
1083
|
-
DLog(@"using sessionKey: %@", sessionKey);
|
|
1084
|
-
DLog(@"using session: %@", session);
|
|
1085
|
-
[FIRTOTPMultiFactorGenerator
|
|
1086
|
-
generateSecretWithMultiFactorSession:session
|
|
1087
|
-
completion:^(FIRTOTPSecret *_Nullable totpSecret,
|
|
1088
|
-
NSError *_Nullable error) {
|
|
1089
|
-
DLog(@"authError: %@", error) if (error) {
|
|
1090
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1091
|
-
}
|
|
1092
|
-
else {
|
|
1093
|
-
NSString *secretKey = totpSecret.sharedSecretKey;
|
|
1094
|
-
DLog(@"secretKey generated: %@", secretKey);
|
|
1095
|
-
cachedTotpSecrets[secretKey] = totpSecret;
|
|
1096
|
-
DLog(@"cachedSecret: %@", cachedTotpSecrets[secretKey]);
|
|
1097
|
-
resolve(@{
|
|
1098
|
-
@"secretKey" : secretKey,
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
}];
|
|
409
|
+
[RNFBAuthHelper generateTotpSecret:appName sessionKey:sessionKey resolve:resolve reject:reject];
|
|
1102
410
|
}
|
|
1103
411
|
|
|
1104
412
|
- (NSString *)generateQrCodeUrl:(NSString *)appName
|
|
1105
413
|
secretKey:(NSString *)secretKey
|
|
1106
414
|
account:(NSString *)account
|
|
1107
415
|
issuer:(NSString *)issuer {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
FIRTOTPSecret *totpSecret = cachedTotpSecrets[secretKey];
|
|
1113
|
-
if (!totpSecret) {
|
|
1114
|
-
RNFBAuthThrowSyncErrorWithCode(@"invalid-multi-factor-secret",
|
|
1115
|
-
@"can't find secret for provided key");
|
|
1116
|
-
}
|
|
1117
|
-
NSString *url = [totpSecret generateQRCodeURLWithAccountName:account issuer:issuer];
|
|
1118
|
-
DLog(@"generateQrCodeUrl got QR Code URL %@", url);
|
|
1119
|
-
return url;
|
|
416
|
+
return [RNFBAuthHelper generateQrCodeUrl:appName
|
|
417
|
+
secretKey:secretKey
|
|
418
|
+
account:account
|
|
419
|
+
issuer:issuer];
|
|
1120
420
|
}
|
|
1121
421
|
|
|
1122
422
|
- (void)openInOtpApp:(NSString *)appName
|
|
1123
423
|
secretKey:(NSString *)secretKey
|
|
1124
424
|
qrCodeUri:(NSString *)qrCodeUri {
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
DLog(@"generateQrCodeUrl using secretKey: %@", secretKey);
|
|
1128
|
-
FIRTOTPSecret *totpSecret = cachedTotpSecrets[secretKey];
|
|
1129
|
-
DLog(@"openInOtpApp using qrCodeUri: %@", qrCodeUri);
|
|
1130
|
-
[totpSecret openInOTPAppWithQRCodeURL:qrCodeUri];
|
|
425
|
+
[RNFBAuthHelper openInOtpApp:appName secretKey:secretKey qrCodeUri:qrCodeUri];
|
|
1131
426
|
}
|
|
1132
427
|
|
|
1133
428
|
- (void)getSession:(NSString *)appName
|
|
1134
429
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1135
430
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1139
|
-
[[user multiFactor] getSessionWithCompletion:^(FIRMultiFactorSession *_Nullable session,
|
|
1140
|
-
NSError *_Nullable error) {
|
|
1141
|
-
if (error != nil) {
|
|
1142
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1143
|
-
return;
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
NSString *sessionId = [NSString stringWithFormat:@"%@", @([session hash])];
|
|
1147
|
-
cachedSessions[sessionId] = session;
|
|
1148
|
-
resolve(sessionId);
|
|
1149
|
-
}];
|
|
431
|
+
[RNFBAuthHelper getSession:appName resolve:resolve reject:reject];
|
|
1150
432
|
}
|
|
1151
433
|
|
|
1152
434
|
- (void)unenrollMultiFactor:(NSString *)appName
|
|
1153
435
|
factorUID:(NSString *)factorUID
|
|
1154
436
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1155
437
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
DLog(@"using instance unenrollMultiFactor: %@", firebaseApp.name);
|
|
1159
|
-
|
|
1160
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1161
|
-
[user.multiFactor unenrollWithFactorUID:factorUID
|
|
1162
|
-
completion:^(NSError *_Nullable error) {
|
|
1163
|
-
if (error != nil) {
|
|
1164
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1165
|
-
return;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
resolve(nil);
|
|
1169
|
-
return;
|
|
1170
|
-
}];
|
|
438
|
+
[RNFBAuthHelper unenrollMultiFactor:appName factorUID:factorUID resolve:resolve reject:reject];
|
|
1171
439
|
}
|
|
1172
440
|
|
|
1173
441
|
- (void)finalizeMultiFactorEnrollment:(NSString *)appName
|
|
@@ -1176,28 +444,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
1176
444
|
displayName:(NSString *_Nullable)displayName
|
|
1177
445
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1178
446
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
credentialWithVerificationID:verificationId
|
|
1186
|
-
verificationCode:verificationCode];
|
|
1187
|
-
FIRMultiFactorAssertion *assertion =
|
|
1188
|
-
[FIRPhoneMultiFactorGenerator assertionWithCredential:credential];
|
|
1189
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1190
|
-
[user.multiFactor enrollWithAssertion:assertion
|
|
1191
|
-
displayName:displayName
|
|
1192
|
-
completion:^(NSError *_Nullable error) {
|
|
1193
|
-
if (error != nil) {
|
|
1194
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1195
|
-
return;
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
|
-
resolve(nil);
|
|
1199
|
-
return;
|
|
1200
|
-
}];
|
|
447
|
+
[RNFBAuthHelper finalizeMultiFactorEnrollment:appName
|
|
448
|
+
verificationId:verificationId
|
|
449
|
+
verificationCode:verificationCode
|
|
450
|
+
displayName:displayName
|
|
451
|
+
resolve:resolve
|
|
452
|
+
reject:reject];
|
|
1201
453
|
}
|
|
1202
454
|
|
|
1203
455
|
- (void)finalizeTotpEnrollment:(NSString *)appName
|
|
@@ -1206,30 +458,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
1206
458
|
displayName:(NSString *_Nullable)displayName
|
|
1207
459
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1208
460
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
DLog(@"using cachedSecret: %@", cachedTotpSecret);
|
|
1216
|
-
FIRTOTPMultiFactorAssertion *assertion =
|
|
1217
|
-
[FIRTOTPMultiFactorGenerator assertionForEnrollmentWithSecret:cachedTotpSecret
|
|
1218
|
-
oneTimePassword:verificationCode];
|
|
1219
|
-
|
|
1220
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1221
|
-
|
|
1222
|
-
[user.multiFactor enrollWithAssertion:assertion
|
|
1223
|
-
displayName:displayName
|
|
1224
|
-
completion:^(NSError *_Nullable error) {
|
|
1225
|
-
if (error != nil) {
|
|
1226
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1227
|
-
return;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
resolve(nil);
|
|
1231
|
-
return;
|
|
1232
|
-
}];
|
|
461
|
+
[RNFBAuthHelper finalizeTotpEnrollment:appName
|
|
462
|
+
totpSecret:totpSecret
|
|
463
|
+
verificationCode:verificationCode
|
|
464
|
+
displayName:displayName
|
|
465
|
+
resolve:resolve
|
|
466
|
+
reject:reject];
|
|
1233
467
|
}
|
|
1234
468
|
|
|
1235
469
|
- (void)verifyPhoneNumber:(NSString *)appName
|
|
@@ -1237,63 +471,21 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
1237
471
|
requestKey:(NSString *)requestKey
|
|
1238
472
|
timeout:(double)timeout
|
|
1239
473
|
forceResend:(BOOL)forceResend {
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
verifyPhoneNumber:phoneNumber
|
|
1246
|
-
UIDelegate:nil
|
|
1247
|
-
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
|
|
1248
|
-
if (error) {
|
|
1249
|
-
NSDictionary *jsError = [self getJSError:error];
|
|
1250
|
-
NSDictionary *body = @{
|
|
1251
|
-
@"type" : @"onVerificationFailed",
|
|
1252
|
-
@"requestKey" : requestKey,
|
|
1253
|
-
@"state" : @{@"error" : jsError},
|
|
1254
|
-
};
|
|
1255
|
-
[RNFBSharedUtils sendJSEventForApp:firebaseApp
|
|
1256
|
-
name:PHONE_AUTH_STATE_CHANGED_EVENT
|
|
1257
|
-
body:body];
|
|
1258
|
-
} else {
|
|
1259
|
-
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
1260
|
-
[defaults setObject:verificationID forKey:@"authVerificationID"];
|
|
1261
|
-
NSDictionary *body = @{
|
|
1262
|
-
@"type" : @"onCodeSent",
|
|
1263
|
-
@"requestKey" : requestKey,
|
|
1264
|
-
@"state" : @{@"verificationId" : verificationID},
|
|
1265
|
-
};
|
|
1266
|
-
[RNFBSharedUtils sendJSEventForApp:firebaseApp
|
|
1267
|
-
name:PHONE_AUTH_STATE_CHANGED_EVENT
|
|
1268
|
-
body:body];
|
|
1269
|
-
}
|
|
1270
|
-
}];
|
|
474
|
+
[RNFBAuthHelper verifyPhoneNumber:appName
|
|
475
|
+
phoneNumber:phoneNumber
|
|
476
|
+
requestKey:requestKey
|
|
477
|
+
timeout:timeout
|
|
478
|
+
forceResend:forceResend];
|
|
1271
479
|
}
|
|
1272
480
|
|
|
1273
481
|
- (void)confirmationResultConfirm:(NSString *)appName
|
|
1274
482
|
verificationCode:(NSString *)verificationCode
|
|
1275
483
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1276
484
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
FIRAuthCredential *credential =
|
|
1283
|
-
[[FIRPhoneAuthProvider providerWithAuth:[FIRAuth authWithApp:firebaseApp]]
|
|
1284
|
-
credentialWithVerificationID:verificationId
|
|
1285
|
-
verificationCode:verificationCode];
|
|
1286
|
-
|
|
1287
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
1288
|
-
signInWithCredential:credential
|
|
1289
|
-
completion:^(FIRAuthDataResult *authResult, NSError *error) {
|
|
1290
|
-
DLog(@"auth error: %long", (long)error.code);
|
|
1291
|
-
if (error) {
|
|
1292
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1293
|
-
} else {
|
|
1294
|
-
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
|
1295
|
-
}
|
|
1296
|
-
}];
|
|
485
|
+
[RNFBAuthHelper confirmationResultConfirm:appName
|
|
486
|
+
verificationCode:verificationCode
|
|
487
|
+
resolve:resolve
|
|
488
|
+
reject:reject];
|
|
1297
489
|
}
|
|
1298
490
|
#endif
|
|
1299
491
|
|
|
@@ -1303,126 +495,26 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
1303
495
|
authSecret:(NSString *)authSecret
|
|
1304
496
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1305
497
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
if (credential == nil) {
|
|
1314
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
1315
|
-
userInfo:(NSMutableDictionary *)@{
|
|
1316
|
-
@"code" : @"invalid-credential",
|
|
1317
|
-
@"message" : @"The supplied auth credential is malformed, "
|
|
1318
|
-
@"has expired or is not currently supported.",
|
|
1319
|
-
}];
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1323
|
-
if (user) {
|
|
1324
|
-
[user linkWithCredential:credential
|
|
1325
|
-
completion:^(FIRAuthDataResult *_Nullable authResult, NSError *_Nullable error) {
|
|
1326
|
-
if (error) {
|
|
1327
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1328
|
-
} else {
|
|
1329
|
-
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
|
1330
|
-
}
|
|
1331
|
-
}];
|
|
1332
|
-
} else {
|
|
1333
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
1334
|
-
}
|
|
498
|
+
[RNFBAuthHelper linkWithCredential:appName
|
|
499
|
+
provider:provider
|
|
500
|
+
authToken:authToken
|
|
501
|
+
authSecret:authSecret
|
|
502
|
+
resolve:resolve
|
|
503
|
+
reject:reject];
|
|
1335
504
|
}
|
|
1336
505
|
|
|
1337
506
|
- (void)linkWithProvider:(NSString *)appName
|
|
1338
507
|
provider:(NSDictionary *)provider
|
|
1339
508
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1340
509
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
NSString *providerId = provider[@"providerId"];
|
|
1344
|
-
if (providerId == nil) {
|
|
1345
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
1346
|
-
userInfo:(NSMutableDictionary *)@{
|
|
1347
|
-
@"code" : @"invalid-credential",
|
|
1348
|
-
@"message" : @"The supplied auth credential is malformed, "
|
|
1349
|
-
@"has expired or is not currently supported.",
|
|
1350
|
-
}];
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
__block FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1354
|
-
if (user == nil) {
|
|
1355
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
1356
|
-
return;
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
__block FIROAuthProvider *builder =
|
|
1360
|
-
[FIROAuthProvider providerWithProviderID:providerId auth:[FIRAuth authWithApp:firebaseApp]];
|
|
1361
|
-
// Add scopes if present
|
|
1362
|
-
if (provider[@"scopes"]) {
|
|
1363
|
-
[builder setScopes:provider[@"scopes"]];
|
|
1364
|
-
}
|
|
1365
|
-
// Add custom parameters if present
|
|
1366
|
-
if (provider[@"parameters"]) {
|
|
1367
|
-
[builder setCustomParameters:provider[@"parameters"]];
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
#if TARGET_OS_IOS
|
|
1371
|
-
[builder getCredentialWithUIDelegate:nil
|
|
1372
|
-
completion:^(FIRAuthCredential *_Nullable credential,
|
|
1373
|
-
NSError *_Nullable error) {
|
|
1374
|
-
if (error) {
|
|
1375
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1376
|
-
return;
|
|
1377
|
-
}
|
|
1378
|
-
if (credential) {
|
|
1379
|
-
[user linkWithCredential:credential
|
|
1380
|
-
completion:^(FIRAuthDataResult *_Nullable authResult,
|
|
1381
|
-
NSError *_Nullable error) {
|
|
1382
|
-
if (error) {
|
|
1383
|
-
[self promiseRejectAuthException:reject
|
|
1384
|
-
error:error];
|
|
1385
|
-
return;
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
// NOTE: This variable has NO PURPOSE AT ALL, it is
|
|
1389
|
-
// only to keep a strong reference to the builder
|
|
1390
|
-
// variable so it is not deallocated prematurely by
|
|
1391
|
-
// ARC.
|
|
1392
|
-
NSString *providerID = builder.providerID;
|
|
1393
|
-
|
|
1394
|
-
[self promiseWithAuthResult:resolve
|
|
1395
|
-
rejecter:reject
|
|
1396
|
-
authResult:authResult];
|
|
1397
|
-
}];
|
|
1398
|
-
}
|
|
1399
|
-
}];
|
|
1400
|
-
#endif
|
|
510
|
+
[RNFBAuthHelper linkWithProvider:appName provider:provider resolve:resolve reject:reject];
|
|
1401
511
|
}
|
|
1402
512
|
|
|
1403
513
|
- (void)unlink:(NSString *)appName
|
|
1404
514
|
providerId:(NSString *)providerId
|
|
1405
515
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1406
516
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1410
|
-
|
|
1411
|
-
if (user) {
|
|
1412
|
-
[user unlinkFromProvider:providerId
|
|
1413
|
-
completion:^(FIRUser *_Nullable _user, NSError *_Nullable error) {
|
|
1414
|
-
if (error) {
|
|
1415
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1416
|
-
} else {
|
|
1417
|
-
[self reloadAndReturnUser:user
|
|
1418
|
-
resolver:resolve
|
|
1419
|
-
rejecter:reject
|
|
1420
|
-
firebaseApp:firebaseApp];
|
|
1421
|
-
}
|
|
1422
|
-
}];
|
|
1423
|
-
} else {
|
|
1424
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
1425
|
-
}
|
|
517
|
+
[RNFBAuthHelper unlink:appName providerId:providerId resolve:resolve reject:reject];
|
|
1426
518
|
}
|
|
1427
519
|
|
|
1428
520
|
- (void)reauthenticateWithCredential:(NSString *)appName
|
|
@@ -1431,620 +523,67 @@ RCT_EXPORT_MODULE(NativeRNFBTurboAuth);
|
|
|
1431
523
|
authSecret:(NSString *)authSecret
|
|
1432
524
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1433
525
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
if (credential == nil) {
|
|
1442
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
1443
|
-
userInfo:(NSMutableDictionary *)@{
|
|
1444
|
-
@"code" : @"invalid-credential",
|
|
1445
|
-
@"message" : @"The supplied auth credential is malformed, "
|
|
1446
|
-
@"has expired or is not currently supported.",
|
|
1447
|
-
}];
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1451
|
-
|
|
1452
|
-
if (user) {
|
|
1453
|
-
[user reauthenticateWithCredential:credential
|
|
1454
|
-
completion:^(FIRAuthDataResult *_Nullable authResult,
|
|
1455
|
-
NSError *_Nullable error) {
|
|
1456
|
-
if (error) {
|
|
1457
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1458
|
-
} else {
|
|
1459
|
-
[self promiseWithAuthResult:resolve
|
|
1460
|
-
rejecter:reject
|
|
1461
|
-
authResult:authResult];
|
|
1462
|
-
}
|
|
1463
|
-
}];
|
|
1464
|
-
} else {
|
|
1465
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
1466
|
-
}
|
|
526
|
+
[RNFBAuthHelper reauthenticateWithCredential:appName
|
|
527
|
+
provider:provider
|
|
528
|
+
authToken:authToken
|
|
529
|
+
authSecret:authSecret
|
|
530
|
+
resolve:resolve
|
|
531
|
+
reject:reject];
|
|
1467
532
|
}
|
|
1468
533
|
|
|
1469
534
|
- (void)reauthenticateWithProvider:(NSString *)appName
|
|
1470
535
|
provider:(NSDictionary *)provider
|
|
1471
536
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1472
537
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
1478
|
-
userInfo:(NSMutableDictionary *)@{
|
|
1479
|
-
@"code" : @"invalid-credential",
|
|
1480
|
-
@"message" : @"The supplied auth credential is malformed, "
|
|
1481
|
-
@"has expired or is not currently supported.",
|
|
1482
|
-
}];
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1485
|
-
__block FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1486
|
-
if (user == nil) {
|
|
1487
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
1488
|
-
return;
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
__block FIROAuthProvider *builder =
|
|
1492
|
-
[FIROAuthProvider providerWithProviderID:providerId auth:[FIRAuth authWithApp:firebaseApp]];
|
|
1493
|
-
// Add scopes if present
|
|
1494
|
-
if (provider[@"scopes"]) {
|
|
1495
|
-
[builder setScopes:provider[@"scopes"]];
|
|
1496
|
-
}
|
|
1497
|
-
// Add custom parameters if present
|
|
1498
|
-
if (provider[@"parameters"]) {
|
|
1499
|
-
[builder setCustomParameters:provider[@"parameters"]];
|
|
1500
|
-
}
|
|
1501
|
-
#if TARGET_OS_IOS
|
|
1502
|
-
[builder getCredentialWithUIDelegate:nil
|
|
1503
|
-
completion:^(FIRAuthCredential *_Nullable credential,
|
|
1504
|
-
NSError *_Nullable error) {
|
|
1505
|
-
if (error) {
|
|
1506
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1507
|
-
return;
|
|
1508
|
-
}
|
|
1509
|
-
if (credential) {
|
|
1510
|
-
[user reauthenticateWithCredential:credential
|
|
1511
|
-
completion:^(
|
|
1512
|
-
FIRAuthDataResult *_Nullable authResult,
|
|
1513
|
-
NSError *_Nullable error) {
|
|
1514
|
-
if (error) {
|
|
1515
|
-
[self promiseRejectAuthException:reject
|
|
1516
|
-
error:error];
|
|
1517
|
-
return;
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
// NOTE: This variable has NO PURPOSE AT
|
|
1521
|
-
// ALL, it is only to keep a strong
|
|
1522
|
-
// reference to the builder variable so it
|
|
1523
|
-
// is not deallocated prematurely by ARC.
|
|
1524
|
-
NSString *providerID = builder.providerID;
|
|
1525
|
-
|
|
1526
|
-
[self promiseWithAuthResult:resolve
|
|
1527
|
-
rejecter:reject
|
|
1528
|
-
authResult:authResult];
|
|
1529
|
-
}];
|
|
1530
|
-
}
|
|
1531
|
-
}];
|
|
1532
|
-
#endif
|
|
538
|
+
[RNFBAuthHelper reauthenticateWithProvider:appName
|
|
539
|
+
provider:provider
|
|
540
|
+
resolve:resolve
|
|
541
|
+
reject:reject];
|
|
1533
542
|
}
|
|
1534
543
|
|
|
1535
544
|
- (void)fetchSignInMethodsForEmail:(NSString *)appName
|
|
1536
545
|
email:(NSString *)email
|
|
1537
546
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1538
547
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
1542
|
-
fetchSignInMethodsForEmail:email
|
|
1543
|
-
completion:^(NSArray<NSString *> *_Nullable providers,
|
|
1544
|
-
NSError *_Nullable error) {
|
|
1545
|
-
if (error) {
|
|
1546
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1547
|
-
} else if (!providers) {
|
|
1548
|
-
NSMutableArray *emptyResponse = [[NSMutableArray alloc] init];
|
|
1549
|
-
resolve(emptyResponse);
|
|
1550
|
-
} else {
|
|
1551
|
-
resolve(providers);
|
|
1552
|
-
}
|
|
1553
|
-
}];
|
|
548
|
+
[RNFBAuthHelper fetchSignInMethodsForEmail:appName email:email resolve:resolve reject:reject];
|
|
1554
549
|
}
|
|
1555
550
|
|
|
1556
551
|
- (void)setLanguageCode:(NSString *)appName code:(NSString *)code {
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
if (code) {
|
|
1560
|
-
[FIRAuth authWithApp:firebaseApp].languageCode = code;
|
|
1561
|
-
} else {
|
|
1562
|
-
[[FIRAuth authWithApp:firebaseApp] useAppLanguage];
|
|
1563
|
-
}
|
|
552
|
+
[RNFBAuthHelper setLanguageCode:appName code:code];
|
|
1564
553
|
}
|
|
1565
554
|
|
|
1566
555
|
- (void)setTenantId:(NSString *)appName
|
|
1567
556
|
tenantId:(NSString *)tenantId
|
|
1568
557
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1569
558
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
[FIRAuth authWithApp:firebaseApp].tenantID = tenantId;
|
|
1573
|
-
resolve([NSNull null]);
|
|
559
|
+
[RNFBAuthHelper setTenantId:appName tenantId:tenantId resolve:resolve reject:reject];
|
|
1574
560
|
}
|
|
1575
561
|
|
|
1576
562
|
- (void)useDeviceLanguage:(NSString *)appName {
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
[[FIRAuth authWithApp:firebaseApp] useAppLanguage];
|
|
563
|
+
[RNFBAuthHelper useDeviceLanguage:appName];
|
|
1580
564
|
}
|
|
1581
565
|
|
|
1582
566
|
- (void)verifyPasswordResetCode:(NSString *)appName
|
|
1583
567
|
code:(NSString *)code
|
|
1584
568
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
1585
569
|
reject:(RCTPromiseRejectBlock)reject {
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
[[FIRAuth authWithApp:firebaseApp]
|
|
1589
|
-
verifyPasswordResetCode:code
|
|
1590
|
-
completion:^(NSString *_Nullable email, NSError *_Nullable error) {
|
|
1591
|
-
if (error) {
|
|
1592
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1593
|
-
} else {
|
|
1594
|
-
resolve(email);
|
|
1595
|
-
}
|
|
1596
|
-
}];
|
|
570
|
+
[RNFBAuthHelper verifyPasswordResetCode:appName code:code resolve:resolve reject:reject];
|
|
1597
571
|
}
|
|
1598
572
|
|
|
1599
573
|
- (void)useEmulator:(NSString *)appName host:(nonnull NSString *)host port:(double)port {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
if (!emulatorConfigs[firebaseApp.name]) {
|
|
1603
|
-
[[FIRAuth authWithApp:firebaseApp] useEmulatorWithHost:host port:(NSInteger)port];
|
|
1604
|
-
emulatorConfigs[firebaseApp.name] = @YES;
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
- (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider
|
|
1609
|
-
token:(NSString *)authToken
|
|
1610
|
-
secret:(NSString *)authTokenSecret
|
|
1611
|
-
firebaseApp:(FIRApp *)firebaseApp {
|
|
1612
|
-
FIRAuthCredential *credential;
|
|
1613
|
-
|
|
1614
|
-
// First check if we cached an authToken
|
|
1615
|
-
if (credentials[authToken] != nil && ![credentials[authToken] isEqual:[NSNull null]]) {
|
|
1616
|
-
credential = credentials[authToken];
|
|
1617
|
-
} else if ([provider compare:@"twitter.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
1618
|
-
credential = [FIRTwitterAuthProvider credentialWithToken:authToken secret:authTokenSecret];
|
|
1619
|
-
} else if ([provider compare:@"facebook.com" options:NSCaseInsensitiveSearch] == NSOrderedSame &&
|
|
1620
|
-
![authTokenSecret isEqualToString:@""]) {
|
|
1621
|
-
credential = [FIROAuthProvider credentialWithProviderID:provider
|
|
1622
|
-
IDToken:authToken
|
|
1623
|
-
rawNonce:authTokenSecret];
|
|
1624
|
-
} else if ([provider compare:@"facebook.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
1625
|
-
credential = [FIRFacebookAuthProvider credentialWithAccessToken:authToken];
|
|
1626
|
-
} else if ([provider compare:@"google.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
1627
|
-
credential = [FIRGoogleAuthProvider credentialWithIDToken:authToken
|
|
1628
|
-
accessToken:authTokenSecret];
|
|
1629
|
-
} else if ([provider compare:@"apple.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
1630
|
-
credential = [FIROAuthProvider credentialWithProviderID:provider
|
|
1631
|
-
IDToken:authToken
|
|
1632
|
-
rawNonce:authTokenSecret];
|
|
1633
|
-
} else if ([provider compare:@"password" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
1634
|
-
credential = [FIREmailAuthProvider credentialWithEmail:authToken password:authTokenSecret];
|
|
1635
|
-
} else if ([provider compare:@"emailLink" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
1636
|
-
credential = [FIREmailAuthProvider credentialWithEmail:authToken link:authTokenSecret];
|
|
1637
|
-
} else if ([provider compare:@"github.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
1638
|
-
credential = [FIRGitHubAuthProvider credentialWithToken:authToken];
|
|
1639
|
-
} else if ([provider compare:@"phone" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
1640
|
-
#if TARGET_OS_IOS
|
|
1641
|
-
DLog(@"using app credGen: %@", firebaseApp.name) credential =
|
|
1642
|
-
[[FIRPhoneAuthProvider providerWithAuth:[FIRAuth authWithApp:firebaseApp]]
|
|
1643
|
-
credentialWithVerificationID:authToken
|
|
1644
|
-
verificationCode:authTokenSecret];
|
|
1645
|
-
#endif
|
|
1646
|
-
} else if ([provider compare:@"oauth" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
|
1647
|
-
NSString *IDToken = authToken.length > 0 ? authToken : nil;
|
|
1648
|
-
NSString *accessToken = authTokenSecret.length > 0 ? authTokenSecret : nil;
|
|
1649
|
-
credential = [FIROAuthProvider credentialWithProviderID:@"oauth"
|
|
1650
|
-
IDToken:IDToken
|
|
1651
|
-
accessToken:accessToken];
|
|
1652
|
-
} else if ([provider hasPrefix:@"oidc."]) {
|
|
1653
|
-
credential = [FIROAuthProvider credentialWithProviderID:provider
|
|
1654
|
-
IDToken:authToken
|
|
1655
|
-
rawNonce:nil];
|
|
1656
|
-
} else {
|
|
1657
|
-
DLog(@"Provider not yet handled: %@", provider);
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
|
-
return credential;
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
// This is here to protect against bugs in the iOS SDK which don't
|
|
1664
|
-
// correctly refresh the user object when performing certain operations
|
|
1665
|
-
- (void)reloadAndReturnUser:(FIRUser *)user
|
|
1666
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
1667
|
-
rejecter:(RCTPromiseRejectBlock)reject
|
|
1668
|
-
firebaseApp:(FIRApp *)firebaseApp {
|
|
1669
|
-
[user reloadWithCompletion:^(NSError *_Nullable error) {
|
|
1670
|
-
if (error) {
|
|
1671
|
-
[self promiseRejectAuthException:reject error:error];
|
|
1672
|
-
} else {
|
|
1673
|
-
[self promiseWithUser:resolve rejecter:reject user:user];
|
|
1674
|
-
}
|
|
1675
|
-
}];
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
|
-
- (void)promiseNoUser:(RCTPromiseResolveBlock)resolve
|
|
1679
|
-
rejecter:(RCTPromiseRejectBlock)reject
|
|
1680
|
-
isError:(BOOL)isError {
|
|
1681
|
-
if (isError) {
|
|
1682
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
1683
|
-
userInfo:(NSMutableDictionary *)@{
|
|
1684
|
-
@"code" : @"no-current-user",
|
|
1685
|
-
@"message" : @"No user currently signed in.",
|
|
1686
|
-
}];
|
|
1687
|
-
} else {
|
|
1688
|
-
resolve([NSNull null]);
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
#if TARGET_OS_IOS
|
|
1693
|
-
- (NSDictionary *)multiFactorResolverToDict:(FIRMultiFactorResolver *)resolver {
|
|
1694
|
-
// Temporarily store the non-serializable session for later
|
|
1695
|
-
NSString *sessionHash = [NSString stringWithFormat:@"%@", @([resolver.session hash])];
|
|
1696
|
-
|
|
1697
|
-
return @{
|
|
1698
|
-
@"hints" : [self convertMultiFactorData:resolver.hints],
|
|
1699
|
-
@"session" : sessionHash,
|
|
1700
|
-
@"auth" : resolver.auth
|
|
1701
|
-
};
|
|
1702
|
-
}
|
|
1703
|
-
#endif
|
|
1704
|
-
|
|
1705
|
-
- (void)promiseRejectAuthException:(RCTPromiseRejectBlock)reject error:(NSError *)error {
|
|
1706
|
-
NSDictionary *jsError = [self getJSError:error];
|
|
1707
|
-
|
|
1708
|
-
[RNFBSharedUtils
|
|
1709
|
-
rejectPromiseWithUserInfo:reject
|
|
1710
|
-
userInfo:(NSMutableDictionary *)@{
|
|
1711
|
-
@"code" : [jsError valueForKey:@"code"],
|
|
1712
|
-
@"message" : [jsError valueForKey:@"message"],
|
|
1713
|
-
@"nativeErrorMessage" : [jsError valueForKey:@"nativeErrorMessage"],
|
|
1714
|
-
@"authCredential" : [jsError valueForKey:@"authCredential"],
|
|
1715
|
-
@"resolver" : [jsError valueForKey:@"resolver"]
|
|
1716
|
-
}];
|
|
1717
|
-
}
|
|
1718
|
-
|
|
1719
|
-
- (NSDictionary *)getJSError:(NSError *)error {
|
|
1720
|
-
NSString *code = AuthErrorCode_toJSErrorCode[error.code];
|
|
1721
|
-
NSString *message = [error localizedDescription];
|
|
1722
|
-
NSString *nativeErrorMessage = [error localizedDescription];
|
|
1723
|
-
|
|
1724
|
-
if (code == nil) code = @"unknown";
|
|
1725
|
-
|
|
1726
|
-
// TODO(Salakar): replace these with a AuthErrorCode_toJSErrorMessage map (like codes now does)
|
|
1727
|
-
switch (error.code) {
|
|
1728
|
-
case FIRAuthErrorCodeInvalidCustomToken:
|
|
1729
|
-
message = @"The custom token format is incorrect. Please check the documentation.";
|
|
1730
|
-
break;
|
|
1731
|
-
case FIRAuthErrorCodeCustomTokenMismatch:
|
|
1732
|
-
message = @"The custom token corresponds to a different audience.";
|
|
1733
|
-
break;
|
|
1734
|
-
case FIRAuthErrorCodeInvalidCredential:
|
|
1735
|
-
message = @"The supplied auth credential is malformed or has expired.";
|
|
1736
|
-
break;
|
|
1737
|
-
case FIRAuthErrorCodeInvalidEmail:
|
|
1738
|
-
message = @"The email address is badly formatted.";
|
|
1739
|
-
break;
|
|
1740
|
-
case FIRAuthErrorCodeWrongPassword:
|
|
1741
|
-
message = @"The password is invalid or the user does not have a password.";
|
|
1742
|
-
break;
|
|
1743
|
-
case FIRAuthErrorCodeUserMismatch:
|
|
1744
|
-
message = @"The supplied credentials do not correspond to the previously signed in user.";
|
|
1745
|
-
break;
|
|
1746
|
-
case FIRAuthErrorCodeRequiresRecentLogin:
|
|
1747
|
-
message = @"This operation is sensitive and requires recent authentication. Log in again "
|
|
1748
|
-
@"before retrying this request.";
|
|
1749
|
-
break;
|
|
1750
|
-
case FIRAuthErrorCodeSecondFactorRequired:
|
|
1751
|
-
message = @"Please complete a second factor challenge to finish signing into this account.";
|
|
1752
|
-
break;
|
|
1753
|
-
case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
|
|
1754
|
-
message = @"An account already exists with the same email address but different sign-in "
|
|
1755
|
-
@"credentials. Sign in using a provider associated with this email address.";
|
|
1756
|
-
break;
|
|
1757
|
-
case FIRAuthErrorCodeEmailAlreadyInUse:
|
|
1758
|
-
message = @"The email address is already in use by another account.";
|
|
1759
|
-
break;
|
|
1760
|
-
case FIRAuthErrorCodeCredentialAlreadyInUse:
|
|
1761
|
-
message = @"This credential is already associated with a different user account.";
|
|
1762
|
-
break;
|
|
1763
|
-
case FIRAuthErrorCodeUserDisabled:
|
|
1764
|
-
message = @"The user account has been disabled by an administrator.";
|
|
1765
|
-
break;
|
|
1766
|
-
case FIRAuthErrorCodeUserTokenExpired:
|
|
1767
|
-
message = @"The user's credential is no longer valid. The user must sign in again.";
|
|
1768
|
-
break;
|
|
1769
|
-
case FIRAuthErrorCodeUserNotFound:
|
|
1770
|
-
message = @"There is no user record corresponding to this identifier. The user may have been "
|
|
1771
|
-
@"deleted.";
|
|
1772
|
-
break;
|
|
1773
|
-
case FIRAuthErrorCodeInvalidUserToken:
|
|
1774
|
-
message = @"The user's credential is no longer valid. The user must sign in again.";
|
|
1775
|
-
break;
|
|
1776
|
-
case FIRAuthErrorCodeWeakPassword:
|
|
1777
|
-
message = @"The given password is invalid.";
|
|
1778
|
-
break;
|
|
1779
|
-
case FIRAuthErrorCodeOperationNotAllowed:
|
|
1780
|
-
message = @"This operation is not allowed. You must enable this service in the console.";
|
|
1781
|
-
break;
|
|
1782
|
-
case FIRAuthErrorCodeNetworkError:
|
|
1783
|
-
message = @"A network error has occurred, please try again.";
|
|
1784
|
-
break;
|
|
1785
|
-
case FIRAuthErrorCodeInternalError:
|
|
1786
|
-
message = @"An internal error has occurred, please try again.";
|
|
1787
|
-
break;
|
|
1788
|
-
case FIRAuthErrorCodeInvalidPhoneNumber:
|
|
1789
|
-
message = @"The format of the phone number provided is incorrect. "
|
|
1790
|
-
@"Please enter the phone number in a format that can be parsed into E.164 format. "
|
|
1791
|
-
@"E.164 phone numbers are written in the format [+][country code][subscriber "
|
|
1792
|
-
@"number including area code].";
|
|
1793
|
-
break;
|
|
1794
|
-
default:
|
|
1795
|
-
break;
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
NSDictionary *authCredentialDict = nil;
|
|
1799
|
-
if ([error userInfo][FIRAuthErrorUserInfoUpdatedCredentialKey] != nil) {
|
|
1800
|
-
FIRAuthCredential *authCredential = [error userInfo][FIRAuthErrorUserInfoUpdatedCredentialKey];
|
|
1801
|
-
authCredentialDict = [self authCredentialToDict:authCredential];
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
NSDictionary *resolverDict = nil;
|
|
1805
|
-
#if TARGET_OS_IOS
|
|
1806
|
-
if ([error userInfo][FIRAuthErrorUserInfoMultiFactorResolverKey] != nil) {
|
|
1807
|
-
FIRMultiFactorResolver *resolver = error.userInfo[FIRAuthErrorUserInfoMultiFactorResolverKey];
|
|
1808
|
-
resolverDict = [self multiFactorResolverToDict:resolver];
|
|
1809
|
-
|
|
1810
|
-
NSString *sessionKey = [NSString stringWithFormat:@"%@", @([resolver.session hash])];
|
|
1811
|
-
cachedResolver[sessionKey] = resolver;
|
|
1812
|
-
}
|
|
1813
|
-
#endif
|
|
1814
|
-
|
|
1815
|
-
return @{
|
|
1816
|
-
@"code" : code,
|
|
1817
|
-
@"message" : message,
|
|
1818
|
-
@"nativeErrorMessage" : nativeErrorMessage,
|
|
1819
|
-
@"authCredential" : authCredentialDict != nil ? (id)authCredentialDict : [NSNull null],
|
|
1820
|
-
@"resolver" : resolverDict != nil ? (id)resolverDict : [NSNull null]
|
|
1821
|
-
};
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
- (void)promiseWithUser:(RCTPromiseResolveBlock)resolve
|
|
1825
|
-
rejecter:(RCTPromiseRejectBlock)reject
|
|
1826
|
-
user:(FIRUser *)user {
|
|
1827
|
-
if (user) {
|
|
1828
|
-
NSDictionary *userDict = [self firebaseUserToDict:user];
|
|
1829
|
-
resolve(userDict);
|
|
1830
|
-
} else {
|
|
1831
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
- (void)promiseWithAuthResult:(RCTPromiseResolveBlock)resolve
|
|
1836
|
-
rejecter:(RCTPromiseRejectBlock)reject
|
|
1837
|
-
authResult:(FIRAuthDataResult *)authResult {
|
|
1838
|
-
if (authResult && authResult.user) {
|
|
1839
|
-
NSMutableDictionary *authResultDict = [NSMutableDictionary dictionary];
|
|
1840
|
-
|
|
1841
|
-
if (authResult.additionalUserInfo) {
|
|
1842
|
-
NSMutableDictionary *additionalUserInfo = [NSMutableDictionary dictionary];
|
|
1843
|
-
|
|
1844
|
-
[additionalUserInfo setValue:@(authResult.additionalUserInfo.isNewUser) forKey:keyNewUser];
|
|
1845
|
-
|
|
1846
|
-
if (authResult.additionalUserInfo.profile) {
|
|
1847
|
-
[additionalUserInfo setValue:authResult.additionalUserInfo.profile forKey:keyProfile];
|
|
1848
|
-
} else {
|
|
1849
|
-
[additionalUserInfo setValue:[NSNull null] forKey:keyProfile];
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
|
-
if (authResult.additionalUserInfo.providerID) {
|
|
1853
|
-
[additionalUserInfo setValue:authResult.additionalUserInfo.providerID forKey:keyProviderId];
|
|
1854
|
-
} else {
|
|
1855
|
-
[additionalUserInfo setValue:[NSNull null] forKey:keyProviderId];
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
|
-
if (authResult.additionalUserInfo.username) {
|
|
1859
|
-
[additionalUserInfo setValue:authResult.additionalUserInfo.username forKey:keyUsername];
|
|
1860
|
-
} else {
|
|
1861
|
-
[additionalUserInfo setValue:[NSNull null] forKey:keyUsername];
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
[authResultDict setValue:additionalUserInfo forKey:keyAdditionalUserInfo];
|
|
1865
|
-
} else {
|
|
1866
|
-
[authResultDict setValue:[NSNull null] forKey:keyAdditionalUserInfo];
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
[authResultDict setValue:[self firebaseUserToDict:authResult.user] forKey:keyUser];
|
|
1870
|
-
resolve(authResultDict);
|
|
1871
|
-
} else {
|
|
1872
|
-
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
|
1873
|
-
}
|
|
574
|
+
[RNFBAuthHelper useEmulator:appName host:host port:port];
|
|
1874
575
|
}
|
|
1875
576
|
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
for (id<FIRUserInfo> userInfo in providerData) {
|
|
1880
|
-
NSMutableDictionary *pData = [NSMutableDictionary dictionary];
|
|
1881
|
-
|
|
1882
|
-
if (userInfo.providerID != nil) {
|
|
1883
|
-
[pData setValue:userInfo.providerID forKey:keyProviderId];
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
if (userInfo.uid != nil) {
|
|
1887
|
-
[pData setValue:userInfo.uid forKey:keyUid];
|
|
1888
|
-
}
|
|
1889
|
-
|
|
1890
|
-
if (userInfo.displayName != nil) {
|
|
1891
|
-
[pData setValue:userInfo.displayName forKey:keyDisplayName];
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
|
-
if (userInfo.photoURL != nil) {
|
|
1895
|
-
[pData setValue:[userInfo.photoURL absoluteString] forKey:keyPhotoUrl];
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1898
|
-
if (userInfo.email != nil) {
|
|
1899
|
-
[pData setValue:userInfo.email forKey:keyEmail];
|
|
1900
|
-
}
|
|
1901
|
-
|
|
1902
|
-
if (userInfo.phoneNumber != nil) {
|
|
1903
|
-
[pData setValue:userInfo.phoneNumber forKey:keyPhoneNumber];
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
[output addObject:pData];
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1909
|
-
return output;
|
|
1910
|
-
}
|
|
577
|
+
#pragma mark -
|
|
578
|
+
#pragma mark Constants
|
|
1911
579
|
|
|
1912
580
|
- (facebook::react::ModuleConstants<JS::NativeRNFBTurboAuth::Constants::Builder>)constantsToExport {
|
|
1913
|
-
return
|
|
581
|
+
return
|
|
582
|
+
[_RCTTypedModuleConstants newWithUnsafeDictionary:[RNFBAuthHelper authConstantsDictionary]];
|
|
1914
583
|
}
|
|
1915
584
|
|
|
1916
585
|
- (facebook::react::ModuleConstants<JS::NativeRNFBTurboAuth::Constants::Builder>)getConstants {
|
|
1917
586
|
return [self constantsToExport];
|
|
1918
587
|
}
|
|
1919
588
|
|
|
1920
|
-
- (NSDictionary *)authConstantsDictionary {
|
|
1921
|
-
NSDictionary *firebaseApps = [FIRApp allApps];
|
|
1922
|
-
NSMutableDictionary *constants = [NSMutableDictionary new];
|
|
1923
|
-
NSMutableDictionary *appLanguage = [NSMutableDictionary new];
|
|
1924
|
-
NSMutableDictionary *appUser = [NSMutableDictionary new];
|
|
1925
|
-
|
|
1926
|
-
for (id key in firebaseApps) {
|
|
1927
|
-
FIRApp *firebaseApp = firebaseApps[key];
|
|
1928
|
-
NSString *appName = firebaseApp.name;
|
|
1929
|
-
FIRUser *user = [FIRAuth authWithApp:firebaseApp].currentUser;
|
|
1930
|
-
|
|
1931
|
-
if ([appName isEqualToString:@"__FIRAPP_DEFAULT"]) {
|
|
1932
|
-
appName = @"[DEFAULT]";
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
|
-
appLanguage[appName] = [FIRAuth authWithApp:firebaseApp].languageCode;
|
|
1936
|
-
|
|
1937
|
-
if (user != nil) {
|
|
1938
|
-
appUser[appName] = [self firebaseUserToDict:user];
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
constants[constAppLanguage] = appLanguage;
|
|
1943
|
-
constants[constAppUser] = appUser;
|
|
1944
|
-
return constants;
|
|
1945
|
-
}
|
|
1946
|
-
|
|
1947
|
-
- (NSDictionary *)firebaseUserToDict:(FIRUser *)user {
|
|
1948
|
-
return @{
|
|
1949
|
-
keyDisplayName : user.displayName ? (id)user.displayName : [NSNull null],
|
|
1950
|
-
keyEmail : user.email ? (id)user.email : [NSNull null],
|
|
1951
|
-
@"emailVerified" : @(user.emailVerified),
|
|
1952
|
-
@"isAnonymous" : @(user.anonymous),
|
|
1953
|
-
@"metadata" : @{
|
|
1954
|
-
@"creationTime" : user.metadata.creationDate
|
|
1955
|
-
? (id) @(round([user.metadata.creationDate timeIntervalSince1970] * 1000.0))
|
|
1956
|
-
: [NSNull null],
|
|
1957
|
-
@"lastSignInTime" : user.metadata.lastSignInDate
|
|
1958
|
-
? (id) @(round([user.metadata.lastSignInDate timeIntervalSince1970] * 1000.0))
|
|
1959
|
-
: [NSNull null],
|
|
1960
|
-
},
|
|
1961
|
-
keyPhoneNumber : user.phoneNumber ? (id)user.phoneNumber : [NSNull null],
|
|
1962
|
-
keyPhotoUrl : user.photoURL ? (id)[user.photoURL absoluteString] : [NSNull null],
|
|
1963
|
-
@"providerData" : [self convertProviderData:user.providerData],
|
|
1964
|
-
keyProviderId : [user.providerID lowercaseString],
|
|
1965
|
-
@"refreshToken" : user.refreshToken,
|
|
1966
|
-
@"tenantId" : user.tenantID ? (id)user.tenantID : [NSNull null],
|
|
1967
|
-
keyUid : user.uid,
|
|
1968
|
-
#if TARGET_OS_IOS
|
|
1969
|
-
@"multiFactor" :
|
|
1970
|
-
@{@"enrolledFactors" : [self convertMultiFactorData:user.multiFactor.enrolledFactors]}
|
|
1971
|
-
#endif
|
|
1972
|
-
};
|
|
1973
|
-
}
|
|
1974
|
-
|
|
1975
|
-
#if TARGET_OS_IOS
|
|
1976
|
-
- (NSArray<NSMutableDictionary *> *)convertMultiFactorData:(NSArray<FIRMultiFactorInfo *> *)hints {
|
|
1977
|
-
NSMutableArray *enrolledFactors = [NSMutableArray array];
|
|
1978
|
-
|
|
1979
|
-
for (FIRMultiFactorInfo *hint in hints) {
|
|
1980
|
-
NSString *enrollmentTime =
|
|
1981
|
-
[[[NSISO8601DateFormatter alloc] init] stringFromDate:hint.enrollmentDate];
|
|
1982
|
-
|
|
1983
|
-
NSMutableDictionary *factorDict = [@{
|
|
1984
|
-
@"uid" : hint.UID,
|
|
1985
|
-
@"factorId" : hint.factorID,
|
|
1986
|
-
@"displayName" : hint.displayName == nil ? [NSNull null] : hint.displayName,
|
|
1987
|
-
@"enrollmentTime" : enrollmentTime,
|
|
1988
|
-
// @deprecated enrollmentDate kept for backwards compatibility, please use enrollmentTime
|
|
1989
|
-
@"enrollmentDate" : enrollmentTime,
|
|
1990
|
-
} mutableCopy];
|
|
1991
|
-
|
|
1992
|
-
if ([hint isKindOfClass:[FIRPhoneMultiFactorInfo class]]) {
|
|
1993
|
-
FIRPhoneMultiFactorInfo *phoneHint = (FIRPhoneMultiFactorInfo *)hint;
|
|
1994
|
-
factorDict[@"phoneNumber"] = phoneHint.phoneNumber;
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
[enrolledFactors addObject:factorDict];
|
|
1998
|
-
}
|
|
1999
|
-
return enrolledFactors;
|
|
2000
|
-
}
|
|
2001
|
-
#endif
|
|
2002
|
-
|
|
2003
|
-
- (NSDictionary *)authCredentialToDict:(FIRAuthCredential *)authCredential {
|
|
2004
|
-
NSString *authCredentialHash = [NSString stringWithFormat:@"%@", @([authCredential hash])];
|
|
2005
|
-
|
|
2006
|
-
// Temporarily store the non-serializable credential for later
|
|
2007
|
-
credentials[authCredentialHash] = authCredential;
|
|
2008
|
-
|
|
2009
|
-
return @{
|
|
2010
|
-
keyProviderId : authCredential.provider,
|
|
2011
|
-
@"token" : authCredentialHash,
|
|
2012
|
-
@"secret" : [NSNull null],
|
|
2013
|
-
};
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
- (FIRActionCodeSettings *)buildActionCodeSettings:(NSDictionary *)actionCodeSettings {
|
|
2017
|
-
FIRActionCodeSettings *settings = [[FIRActionCodeSettings alloc] init];
|
|
2018
|
-
|
|
2019
|
-
NSString *url = actionCodeSettings[keyUrl];
|
|
2020
|
-
[settings setURL:[NSURL URLWithString:url]];
|
|
2021
|
-
|
|
2022
|
-
if (actionCodeSettings[keyLinkDomain]) {
|
|
2023
|
-
NSString *linkDomain = actionCodeSettings[keyLinkDomain];
|
|
2024
|
-
[settings setLinkDomain:linkDomain];
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
if (actionCodeSettings[keyHandleCodeInApp]) {
|
|
2028
|
-
BOOL handleCodeInApp = [actionCodeSettings[keyHandleCodeInApp] boolValue];
|
|
2029
|
-
[settings setHandleCodeInApp:handleCodeInApp];
|
|
2030
|
-
}
|
|
2031
|
-
|
|
2032
|
-
if (actionCodeSettings[keyAndroid]) {
|
|
2033
|
-
NSDictionary *android = actionCodeSettings[keyAndroid];
|
|
2034
|
-
NSString *packageName = android[keyPackageName];
|
|
2035
|
-
NSString *minimumVersion = android[keyMinVersion];
|
|
2036
|
-
BOOL installApp = [android[keyInstallApp] boolValue];
|
|
2037
|
-
[settings setAndroidPackageName:packageName
|
|
2038
|
-
installIfNotAvailable:installApp
|
|
2039
|
-
minimumVersion:minimumVersion];
|
|
2040
|
-
}
|
|
2041
|
-
|
|
2042
|
-
if (actionCodeSettings[keyIOS]) {
|
|
2043
|
-
NSDictionary *ios = actionCodeSettings[keyIOS];
|
|
2044
|
-
[settings setIOSBundleID:ios[keyBundleId]];
|
|
2045
|
-
}
|
|
2046
|
-
|
|
2047
|
-
return settings;
|
|
2048
|
-
}
|
|
2049
|
-
|
|
2050
589
|
@end
|