-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add tvOS support #8111
feat: add tvOS support #8111
Changes from 4 commits
5514099
610b247
8590777
ac87402
6c79987
be74e45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,18 +55,18 @@ - (void)configure:(FIRApp *)app | |
} | ||
|
||
if ([providerName isEqualToString:@"appAttest"]) { | ||
if (@available(iOS 14.0, macCatalyst 14.0, tvOS 15.0, watchOS 9.0, *)) { | ||
if (@available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 15.0, watchOS 9.0, *)) { | ||
self.delegateProvider = [[FIRAppAttestProvider alloc] initWithApp:app]; | ||
} else { | ||
// This is not a valid configuration. | ||
DLog(@"AppAttest unavailable: it requires iOS14+, macCatalyst14+ or tvOS15+. Installing " | ||
DLog(@"AppAttest unavailable: it requires iOS14+, macOS 11+, macCatalyst14+ or tvOS15+. Installing " | ||
@"debug provider to guarantee invalid tokens in this invalid configuration."); | ||
self.delegateProvider = [[FIRAppCheckDebugProvider alloc] initWithApp:app]; | ||
} | ||
} | ||
|
||
if ([providerName isEqualToString:@"appAttestWithDeviceCheckFallback"]) { | ||
if (@available(iOS 14.0, *)) { | ||
if (@available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 15.0, watchOS 9.0, *)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should have been guarded for all the platforms during initial implementation, oversight |
||
self.delegateProvider = [[FIRAppAttestProvider alloc] initWithApp:app]; | ||
} else { | ||
self.delegateProvider = [[FIRDeviceCheckProvider alloc] initWithApp:app]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,8 +55,10 @@ | |
static __strong NSMutableDictionary *emulatorConfigs; | ||
// Used for caching credentials between method calls. | ||
static __strong NSMutableDictionary<NSString *, FIRAuthCredential *> *credentials; | ||
#if TARGET_OS_IOS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all the multifactor (and phone) stuff is guarded this way, example: https://github.com/firebase/firebase-ios-sdk/blob/ae2554220afb03a5d6fc389c28a86061a12c7caa/FirebaseAuth/Sources/ObjC/FIRMultiFactorConstants.m#L18 |
||
static __strong NSMutableDictionary<NSString *, FIRMultiFactorResolver *> *cachedResolver; | ||
static __strong NSMutableDictionary<NSString *, FIRMultiFactorSession *> *cachedSessions; | ||
#endif | ||
|
||
@implementation RNFBAuthModule | ||
#pragma mark - | ||
|
@@ -76,8 +78,10 @@ - (id)init { | |
idTokenHandlers = [[NSMutableDictionary alloc] init]; | ||
emulatorConfigs = [[NSMutableDictionary alloc] init]; | ||
credentials = [[NSMutableDictionary alloc] init]; | ||
#if TARGET_OS_IOS | ||
cachedResolver = [[NSMutableDictionary alloc] init]; | ||
cachedSessions = [[NSMutableDictionary alloc] init]; | ||
#endif | ||
}); | ||
return self; | ||
} | ||
|
@@ -103,8 +107,10 @@ - (void)invalidate { | |
[idTokenHandlers removeAllObjects]; | ||
|
||
[credentials removeAllObjects]; | ||
#if TARGET_OS_IOS | ||
[cachedResolver removeAllObjects]; | ||
[cachedSessions removeAllObjects]; | ||
#endif | ||
} | ||
|
||
#pragma mark - | ||
|
@@ -415,6 +421,7 @@ - (void)invalidate { | |
} | ||
} | ||
|
||
#if TARGET_OS_IOS | ||
RCT_EXPORT_METHOD(updatePhoneNumber | ||
: (FIRApp *)firebaseApp | ||
: (NSString *)provider | ||
|
@@ -455,6 +462,7 @@ - (void)invalidate { | |
[self promiseNoUser:resolve rejecter:reject isError:YES]; | ||
} | ||
} | ||
#endif | ||
|
||
RCT_EXPORT_METHOD(updateProfile | ||
: (FIRApp *)firebaseApp | ||
|
@@ -617,6 +625,7 @@ - (void)invalidate { | |
[builder setCustomParameters:provider[@"customParameters"]]; | ||
} | ||
|
||
#if TARGET_OS_IOS | ||
[builder getCredentialWithUIDelegate:nil | ||
completion:^(FIRAuthCredential *_Nullable credential, | ||
NSError *_Nullable error) { | ||
|
@@ -647,6 +656,7 @@ - (void)invalidate { | |
}]; | ||
} | ||
}]; | ||
#endif | ||
} | ||
|
||
RCT_EXPORT_METHOD(confirmPasswordReset | ||
|
@@ -817,6 +827,7 @@ - (void)invalidate { | |
}]; | ||
} | ||
|
||
#if TARGET_OS_IOS | ||
RCT_EXPORT_METHOD(signInWithPhoneNumber | ||
: (FIRApp *)firebaseApp | ||
: (NSString *)phoneNumber | ||
|
@@ -1053,6 +1064,7 @@ - (void)invalidate { | |
} | ||
}]; | ||
} | ||
#endif | ||
|
||
RCT_EXPORT_METHOD(linkWithCredential | ||
: (FIRApp *)firebaseApp | ||
|
@@ -1122,6 +1134,7 @@ - (void)invalidate { | |
[builder setCustomParameters:provider[@"parameters"]]; | ||
} | ||
|
||
#if TARGET_OS_IOS | ||
[builder getCredentialWithUIDelegate:nil | ||
completion:^(FIRAuthCredential *_Nullable credential, | ||
NSError *_Nullable error) { | ||
|
@@ -1151,6 +1164,7 @@ - (void)invalidate { | |
}]; | ||
} | ||
}]; | ||
#endif | ||
} | ||
|
||
RCT_EXPORT_METHOD(unlink | ||
|
@@ -1248,7 +1262,7 @@ - (void)invalidate { | |
if (provider[@"parameters"]) { | ||
[builder setCustomParameters:provider[@"parameters"]]; | ||
} | ||
|
||
#if TARGET_OS_IOS | ||
[builder getCredentialWithUIDelegate:nil | ||
completion:^(FIRAuthCredential *_Nullable credential, | ||
NSError *_Nullable error) { | ||
|
@@ -1279,6 +1293,7 @@ - (void)invalidate { | |
}]; | ||
} | ||
}]; | ||
#endif | ||
} | ||
|
||
RCT_EXPORT_METHOD(fetchSignInMethodsForEmail | ||
|
@@ -1375,10 +1390,12 @@ - (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider | |
} else if ([provider compare:@"github.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) { | ||
credential = [FIRGitHubAuthProvider credentialWithToken:authToken]; | ||
} else if ([provider compare:@"phone" options:NSCaseInsensitiveSearch] == NSOrderedSame) { | ||
#if TARGET_OS_IOS | ||
DLog(@"using app credGen: %@", firebaseApp.name) credential = | ||
[[FIRPhoneAuthProvider providerWithAuth:[FIRAuth authWithApp:firebaseApp]] | ||
credentialWithVerificationID:authToken | ||
verificationCode:authTokenSecret]; | ||
#endif | ||
} else if ([provider compare:@"oauth" options:NSCaseInsensitiveSearch] == NSOrderedSame) { | ||
credential = [FIROAuthProvider credentialWithProviderID:@"oauth" | ||
IDToken:authToken | ||
|
@@ -1423,6 +1440,7 @@ - (void)promiseNoUser:(RCTPromiseResolveBlock)resolve | |
} | ||
} | ||
|
||
#if TARGET_OS_IOS | ||
- (NSDictionary *)multiFactorResolverToDict:(FIRMultiFactorResolver *)resolver { | ||
// Temporarily store the non-serializable session for later | ||
NSString *sessionHash = [NSString stringWithFormat:@"%@", @([resolver.session hash])]; | ||
|
@@ -1433,6 +1451,7 @@ - (NSDictionary *)multiFactorResolverToDict:(FIRMultiFactorResolver *)resolver { | |
@"auth" : resolver.auth | ||
}; | ||
} | ||
#endif | ||
|
||
- (NSString *)getJSFactorId:(NSString *)factorId { | ||
if ([factorId isEqualToString:@"1"]) { | ||
|
@@ -1542,14 +1561,17 @@ - (NSDictionary *)getJSError:(NSError *)error { | |
authCredentialDict = [self authCredentialToDict:authCredential]; | ||
} | ||
|
||
|
||
NSDictionary *resolverDict = nil; | ||
#if TARGET_OS_IOS | ||
if ([error userInfo][FIRAuthErrorUserInfoMultiFactorResolverKey] != nil) { | ||
FIRMultiFactorResolver *resolver = error.userInfo[FIRAuthErrorUserInfoMultiFactorResolverKey]; | ||
resolverDict = [self multiFactorResolverToDict:resolver]; | ||
|
||
NSString *sessionKey = [NSString stringWithFormat:@"%@", @([resolver.session hash])]; | ||
cachedResolver[sessionKey] = resolver; | ||
} | ||
#endif | ||
|
||
return @{ | ||
@"code" : code, | ||
|
@@ -1696,11 +1718,14 @@ - (NSDictionary *)firebaseUserToDict:(FIRUser *)user { | |
@"refreshToken" : user.refreshToken, | ||
@"tenantId" : user.tenantID ? (id)user.tenantID : [NSNull null], | ||
keyUid : user.uid, | ||
#if TARGET_OS_IOS | ||
@"multiFactor" : | ||
@{@"enrolledFactors" : [self convertMultiFactorData:user.multiFactor.enrolledFactors]} | ||
#endif | ||
}; | ||
} | ||
|
||
#if TARGET_OS_IOS | ||
- (NSArray<NSMutableDictionary *> *)convertMultiFactorData:(NSArray<FIRMultiFactorInfo *> *)hints { | ||
NSMutableArray *enrolledFactors = [NSMutableArray array]; | ||
|
||
|
@@ -1720,6 +1745,7 @@ - (NSDictionary *)firebaseUserToDict:(FIRUser *)user { | |
} | ||
return enrolledFactors; | ||
} | ||
#endif | ||
|
||
- (NSDictionary *)authCredentialToDict:(FIRAuthCredential *)authCredential { | ||
NSString *authCredentialHash = [NSString stringWithFormat:@"%@", @([authCredential hash])]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just an oversight before, min versions guided by https://firebase.google.com/docs/ios/learn-more#firebase_library_support_by_platform