From b383d4e7330f7f79e28267124e7da4d24fc13abb Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 2 Jan 2024 10:56:43 -0800 Subject: [PATCH] [auth-swift] Restore Objective-C defined public globals and typedefs (#12228) --- FirebaseAuth.podspec | 1 + FirebaseAuth/Sources/ObjC/FIRAuth.m | 19 ++ FirebaseAuth/Sources/ObjC/FIRAuthErrorUtils.m | 36 +++ FirebaseAuth/Sources/ObjC/FIRAuthProvider.m | 66 +++++ .../Sources/ObjC/FIRMultiFactorConstants.m | 27 ++ .../Public/FirebaseAuth/FIRAuthErrors.h | 60 ++++ .../FirebaseAuth/FIREmailAuthProvider.h | 39 +++ .../FirebaseAuth/FIRFacebookAuthProvider.h | 33 +++ .../FirebaseAuth/FIRFederatedAuthProvider.h | 32 +++ .../FirebaseAuth/FIRGameCenterAuthProvider.h | 43 +++ .../FirebaseAuth/FIRGitHubAuthProvider.h | 31 ++ .../FirebaseAuth/FIRGoogleAuthProvider.h | 31 ++ .../Public/FirebaseAuth/FIRMultiFactor.h | 17 +- .../FirebaseAuth/FIRPhoneAuthProvider.h | 47 ++++ .../FirebaseAuth/FIRTwitterAuthProvider.h | 30 ++ .../Sources/Public/FirebaseAuth/FIRUser.h | 71 +++++ .../Public/FirebaseAuth/FirebaseAuth.h | 10 +- FirebaseAuth/Sources/Swift/Auth/Auth.swift | 5 + .../Swift/Utilities/AuthErrorUtils.swift | 21 +- .../Utilities/FIRAuthRecaptchaVerifier.h | 79 ------ .../Utilities/FIRAuthRecaptchaVerifier.m | 264 ------------------ FirebaseAuth/Tests/Unit/ObjCGlobalTests.m | 51 ++++ .../Tests/Unit/SwiftGlobalTests.swift | 50 ++++ FirebaseAuth/Tests/UnitObjC/ObjCAPITests.m | 17 -- Package.swift | 13 + 25 files changed, 712 insertions(+), 381 deletions(-) create mode 100644 FirebaseAuth/Sources/ObjC/FIRAuth.m create mode 100644 FirebaseAuth/Sources/ObjC/FIRAuthErrorUtils.m create mode 100644 FirebaseAuth/Sources/ObjC/FIRAuthProvider.m create mode 100644 FirebaseAuth/Sources/ObjC/FIRMultiFactorConstants.m create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuthErrors.h create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIREmailAuthProvider.h create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIRFacebookAuthProvider.h create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIRFederatedAuthProvider.h create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIRGameCenterAuthProvider.h create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIRGitHubAuthProvider.h create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIRGoogleAuthProvider.h create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIRPhoneAuthProvider.h create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIRTwitterAuthProvider.h create mode 100644 FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h delete mode 100644 FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.h delete mode 100644 FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.m create mode 100644 FirebaseAuth/Tests/Unit/ObjCGlobalTests.m create mode 100644 FirebaseAuth/Tests/Unit/SwiftGlobalTests.swift delete mode 100644 FirebaseAuth/Tests/UnitObjC/ObjCAPITests.m diff --git a/FirebaseAuth.podspec b/FirebaseAuth.podspec index 6783b9fd2ae..b4135dde839 100644 --- a/FirebaseAuth.podspec +++ b/FirebaseAuth.podspec @@ -37,6 +37,7 @@ supports email and password accounts, as well as several 3rd party authenticatio source = 'FirebaseAuth/Sources/' s.source_files = [ source + 'Swift/**/*.swift', + source + 'ObjC/**/*.m', # Implementations for deprecated global symbols source + 'Public/FirebaseAuth/*.h' ] s.public_header_files = source + 'Public/FirebaseAuth/*.h' diff --git a/FirebaseAuth/Sources/ObjC/FIRAuth.m b/FirebaseAuth/Sources/ObjC/FIRAuth.m new file mode 100644 index 00000000000..d3b6c5f9f21 --- /dev/null +++ b/FirebaseAuth/Sources/ObjC/FIRAuth.m @@ -0,0 +1,19 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +const NSNotificationName FIRAuthStateDidChangeNotification = @"FIRAuthStateDidChangeNotification"; diff --git a/FirebaseAuth/Sources/ObjC/FIRAuthErrorUtils.m b/FirebaseAuth/Sources/ObjC/FIRAuthErrorUtils.m new file mode 100644 index 00000000000..508bf6b03f3 --- /dev/null +++ b/FirebaseAuth/Sources/ObjC/FIRAuthErrorUtils.m @@ -0,0 +1,36 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +NSString *const FIRAuthErrorDomain = @"FIRAuthErrorDomain"; + +NSString *const FIRAuthInternalErrorDomain = @"FIRAuthInternalErrorDomain"; + +NSString *const FIRAuthErrorUserInfoDeserializedResponseKey = + @"FIRAuthErrorUserInfoDeserializedResponseKey"; + +NSString *const FIRAuthErrorUserInfoDataKey = @"FIRAuthErrorUserInfoDataKey"; + +NSString *const FIRAuthErrorUserInfoEmailKey = @"FIRAuthErrorUserInfoEmailKey"; + +NSString *const FIRAuthErrorUserInfoUpdatedCredentialKey = + @"FIRAuthErrorUserInfoUpdatedCredentialKey"; + +NSString *const FIRAuthErrorUserInfoNameKey = @"FIRAuthErrorUserInfoNameKey"; + +NSString *const FIRAuthErrorUserInfoMultiFactorResolverKey = + @"FIRAuthErrorUserInfoMultiFactorResolverKey"; diff --git a/FirebaseAuth/Sources/ObjC/FIRAuthProvider.m b/FirebaseAuth/Sources/ObjC/FIRAuthProvider.m new file mode 100644 index 00000000000..6192ad69e59 --- /dev/null +++ b/FirebaseAuth/Sources/ObjC/FIRAuthProvider.m @@ -0,0 +1,66 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#pragma mark - Provider ID constants + +// Declared 'extern' in FIRGoogleAuthProvider.h +NSString *const FIRGoogleAuthProviderID = @"google.com"; + +// Declared 'extern' in FIRFacebookAuthProvider.h +NSString *const FIRFacebookAuthProviderID = @"facebook.com"; + +// Declared 'extern' in FIREmailAuthProvider.h +NSString *const FIREmailAuthProviderID = @"password"; + +// Declared 'extern' in FIRTwitterAuthProvider.h +NSString *const FIRTwitterAuthProviderID = @"twitter.com"; + +// Declared 'extern' in FIRGitHubAuthProvider.h +NSString *const FIRGitHubAuthProviderID = @"github.com"; + +// Declared 'extern' in FIRPhoneAuthProvider.h +NSString *const FIRPhoneAuthProviderID = @"phone"; + +// Declared 'extern' in FIRGameCenterAuthProvider.h +NSString *const FIRGameCenterAuthProviderID = @"gc.apple.com"; + +#pragma mark - sign-in methods constants + +// Declared 'extern' in FIRGoogleAuthProvider.h +NSString *const FIRGoogleAuthSignInMethod = @"google.com"; + +// Declared 'extern' in FIREmailAuthProvider.h +NSString *const FIREmailPasswordAuthSignInMethod = @"password"; + +// Declared 'extern' in FIREmailAuthProvider.h +NSString *const FIREmailLinkAuthSignInMethod = @"emailLink"; + +// Declared 'extern' in FIRTwitterAuthProvider.h +NSString *const FIRTwitterAuthSignInMethod = @"twitter.com"; + +// Declared 'extern' in FIRFacebookAuthProvider.h +NSString *const FIRFacebookAuthSignInMethod = @"facebook.com"; + +// Declared 'extern' in FIRGitHubAuthProvider.h +NSString *const FIRGitHubAuthSignInMethod = @"github.com"; + +// Declared 'extern' in FIRPhoneAuthProvider.h +NSString *const FIRPhoneAuthSignInMethod = @"phone"; + +// Declared 'extern' in FIRGameCenterAuthProvider.h +NSString *const FIRGameCenterAuthSignInMethod = @"gc.apple.com"; diff --git a/FirebaseAuth/Sources/ObjC/FIRMultiFactorConstants.m b/FirebaseAuth/Sources/ObjC/FIRMultiFactorConstants.m new file mode 100644 index 00000000000..4862a485884 --- /dev/null +++ b/FirebaseAuth/Sources/ObjC/FIRMultiFactorConstants.m @@ -0,0 +1,27 @@ +/* + * Copyright 2019 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#if TARGET_OS_IOS + +#import + +#pragma mark - Multi Factor ID constants + +NSString *const FIRPhoneMultiFactorID = @"phone"; +NSString *const FIRTOTPMultiFactorID = @"totp"; + +#endif diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuthErrors.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuthErrors.h new file mode 100644 index 00000000000..12e57d9a3a8 --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuthErrors.h @@ -0,0 +1,60 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + @brief The Firebase Auth error domain. + */ +extern NSString *const FIRAuthErrorDomain NS_SWIFT_NAME(AuthErrorDomain); + +/** + @brief The name of the key for the error short string of an error code. + */ +extern NSString *const FIRAuthErrorUserInfoNameKey NS_SWIFT_NAME(AuthErrorUserInfoNameKey); + +/** + @brief Errors with one of the following three codes: + - `AuthErrorCodeAccountExistsWithDifferentCredential` + - `AuthErrorCodeCredentialAlreadyInUse` + - `AuthErrorCodeEmailAlreadyInUse` + may contain an `NSError.userInfo` dictinary object which contains this key. The value + associated with this key is an NSString of the email address of the account that already + exists. + */ +extern NSString *const FIRAuthErrorUserInfoEmailKey NS_SWIFT_NAME(AuthErrorUserInfoEmailKey); + +/** + @brief The key used to read the updated Auth credential from the userInfo dictionary of the + NSError object returned. This is the updated auth credential the developer should use for + recovery if applicable. + */ +// clang-format off +// clang-format12 will merge lines and exceed 100 character limit. +extern NSString *const FIRAuthErrorUserInfoUpdatedCredentialKey + NS_SWIFT_NAME(AuthErrorUserInfoUpdatedCredentialKey); + +/** + @brief The key used to read the MFA resolver from the userInfo dictionary of the NSError object + returned when 2FA is required for sign-incompletion. + */ +extern NSString *const FIRAuthErrorUserInfoMultiFactorResolverKey + NS_SWIFT_NAME(AuthErrorUserInfoMultiFactorResolverKey); +// clang-format on + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIREmailAuthProvider.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIREmailAuthProvider.h new file mode 100644 index 00000000000..1d05d9a3010 --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIREmailAuthProvider.h @@ -0,0 +1,39 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN +/** + @brief A string constant identifying the email & password identity provider. + */ +extern NSString *const FIREmailAuthProviderID NS_SWIFT_NAME(EmailAuthProviderID); + +/** + @brief A string constant identifying the email-link sign-in method. + */ +extern NSString *const FIREmailLinkAuthSignInMethod NS_SWIFT_NAME(EmailLinkAuthSignInMethod); + +/** + @brief A string constant identifying the email & password sign-in method. + */ +// clang-format off +// clang-format12 merges the next two lines. +extern NSString *const FIREmailPasswordAuthSignInMethod + NS_SWIFT_NAME(EmailPasswordAuthSignInMethod); +// clang-format on + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRFacebookAuthProvider.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRFacebookAuthProvider.h new file mode 100644 index 00000000000..5c95f8bd184 --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRFacebookAuthProvider.h @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class FIRAuthCredential; + +NS_ASSUME_NONNULL_BEGIN + +/** + @brief A string constant identifying the Facebook identity provider. + */ +extern NSString *const FIRFacebookAuthProviderID NS_SWIFT_NAME(FacebookAuthProviderID); + +/** + @brief A string constant identifying the Facebook sign-in method. + */ +extern NSString *const _Nonnull FIRFacebookAuthSignInMethod NS_SWIFT_NAME(FacebookAuthSignInMethod); + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRFederatedAuthProvider.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRFederatedAuthProvider.h new file mode 100644 index 00000000000..89ff2c16aae --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRFederatedAuthProvider.h @@ -0,0 +1,32 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class FIRAuthCredential; + +NS_ASSUME_NONNULL_BEGIN + +/** @typedef FIRAuthCredentialCallback + @brief The type of block invoked when obtaining an auth credential. + @param credential The credential obtained. + @param error The error that occurred if any. + */ +typedef void (^FIRAuthCredentialCallback)(FIRAuthCredential *_Nullable credential, + NSError *_Nullable error) + NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead."); + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRGameCenterAuthProvider.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRGameCenterAuthProvider.h new file mode 100644 index 00000000000..c984f4f75c9 --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRGameCenterAuthProvider.h @@ -0,0 +1,43 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class FIRAuthCredential; + +NS_ASSUME_NONNULL_BEGIN + +/** + @brief A string constant identifying the Game Center identity provider. + */ +extern NSString *const FIRGameCenterAuthProviderID NS_SWIFT_NAME(GameCenterAuthProviderID); + +/** + @brief A string constant identifying the Game Center sign-in method. + */ +extern NSString *const _Nonnull FIRGameCenterAuthSignInMethod NS_SWIFT_NAME( + GameCenterAuthSignInMethod); + +/** @typedef FIRGameCenterCredentialCallback + @brief The type of block invoked when the Game Center credential code has finished. + @param credential On success, the credential will be provided, nil otherwise. + @param error On error, the error that occurred, nil otherwise. + */ +typedef void (^FIRGameCenterCredentialCallback)(FIRAuthCredential *_Nullable credential, + NSError *_Nullable error) + NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead."); + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRGitHubAuthProvider.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRGitHubAuthProvider.h new file mode 100644 index 00000000000..8e5663f2998 --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRGitHubAuthProvider.h @@ -0,0 +1,31 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + @brief A string constant identifying the GitHub identity provider. + */ +extern NSString *const FIRGitHubAuthProviderID NS_SWIFT_NAME(GitHubAuthProviderID); + +/** + @brief A string constant identifying the GitHub sign-in method. + */ +extern NSString *const _Nonnull FIRGitHubAuthSignInMethod NS_SWIFT_NAME(GitHubAuthSignInMethod); + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRGoogleAuthProvider.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRGoogleAuthProvider.h new file mode 100644 index 00000000000..c29d6dac613 --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRGoogleAuthProvider.h @@ -0,0 +1,31 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + @brief A string constant identifying the Google identity provider. + */ +extern NSString *const FIRGoogleAuthProviderID NS_SWIFT_NAME(GoogleAuthProviderID); + +/** + @brief A string constant identifying the Google sign-in method. + */ +extern NSString *const _Nonnull FIRGoogleAuthSignInMethod NS_SWIFT_NAME(GoogleAuthSignInMethod); + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRMultiFactor.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRMultiFactor.h index e793eadbd20..aae0db8ab6f 100644 --- a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRMultiFactor.h +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRMultiFactor.h @@ -17,9 +17,6 @@ #import @class FIRMultiFactorSession; -@class FIRMultiFactorInfo; -@class FIRMultiFactorAssertion; -@class FIRAuthProtoMFAEnrollment; NS_ASSUME_NONNULL_BEGIN @@ -34,12 +31,18 @@ typedef void (^FIRMultiFactorSessionCallback)(FIRMultiFactorSession *_Nullable s NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.") API_UNAVAILABLE(macos, tvos, watchos); -// TODO: get rid of extern /** - @brief The string identifier for second factors. e.g. "phone". + @brief The string identifier for using phone as a second factor. This constant is available on iOS only. */ -// extern NSString *const _Nonnull FIRPhoneMultiFactorID NS_SWIFT_NAME(PhoneMultiFactorID) -// API_UNAVAILABLE(macos, tvos, watchos); +extern NSString *const _Nonnull FIRPhoneMultiFactorID NS_SWIFT_NAME(PhoneMultiFactorID) + API_UNAVAILABLE(macos, tvos, watchos); + +/** + @brief The string identifier for using TOTP as a second factor. + This constant is available on iOS only. +*/ +extern NSString *const _Nonnull FIRTOTPMultiFactorID NS_SWIFT_NAME(TOTPMultiFactorID) + API_UNAVAILABLE(macos, tvos, watchos); NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRPhoneAuthProvider.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRPhoneAuthProvider.h new file mode 100644 index 00000000000..982230b59b4 --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRPhoneAuthProvider.h @@ -0,0 +1,47 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +/** @var FIRPhoneAuthProviderID + @brief A string constant identifying the phone identity provider. + This constant is available on iOS only. + */ +extern NSString *const FIRPhoneAuthProviderID NS_SWIFT_NAME(PhoneAuthProviderID) + API_UNAVAILABLE(macos, tvos, watchos); + +/** @var FIRPhoneAuthProviderID + @brief A string constant identifying the phone sign-in method. + This constant is available on iOS only. + */ +extern NSString *const _Nonnull FIRPhoneAuthSignInMethod NS_SWIFT_NAME(PhoneAuthSignInMethod) + API_UNAVAILABLE(macos, tvos, watchos); + +/** @typedef FIRVerificationResultCallback + @brief The type of block invoked when a request to send a verification code has finished. + This type is available on iOS only. + + @param verificationID On success, the verification ID provided, nil otherwise. + @param error On error, the error that occurred, nil otherwise. + */ +typedef void (^FIRVerificationResultCallback)(NSString *_Nullable verificationID, + NSError *_Nullable error) + NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.") + API_UNAVAILABLE(macos, tvos, watchos); + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRTwitterAuthProvider.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRTwitterAuthProvider.h new file mode 100644 index 00000000000..cb6283fff36 --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRTwitterAuthProvider.h @@ -0,0 +1,30 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + @brief A string constant identifying the Twitter identity provider. + */ +extern NSString *const FIRTwitterAuthProviderID NS_SWIFT_NAME(TwitterAuthProviderID); +/** + @brief A string constant identifying the Twitter sign-in method. + */ +extern NSString *const _Nonnull FIRTwitterAuthSignInMethod NS_SWIFT_NAME(TwitterAuthSignInMethod); + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h new file mode 100644 index 00000000000..96f828c1670 --- /dev/null +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h @@ -0,0 +1,71 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class FIRAuthTokenResult; +@class FIRPhoneAuthCredential; +@class FIRUserProfileChangeRequest; +@class FIRUserMetadata; +@protocol FIRAuthUIDelegate; + +NS_ASSUME_NONNULL_BEGIN + +/** @typedef FIRAuthTokenCallback + @brief The type of block called when a token is ready for use. + @see `User.getIDToken()` + @see `User.idTokenForcingRefresh(_:)` + + @param token Optionally; an access token if the request was successful. + @param error Optionally; the error which occurred - or nil if the request was successful. + + @remarks One of `token` or `error` will always be non-nil. + */ +typedef void (^FIRAuthTokenCallback)(NSString *_Nullable token, NSError *_Nullable error) + NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead."); + +/** @typedef FIRAuthTokenResultCallback + @brief The type of block called when a token is ready for use. + @see `User.getIDToken()` + @see `User.idTokenForcingRefresh(_:)` + + @param tokenResult Optionally; an object containing the raw access token string as well as other + useful data pertaining to the token. + @param error Optionally; the error which occurred - or nil if the request was successful. + + @remarks One of `token` or `error` will always be non-nil. + */ +typedef void (^FIRAuthTokenResultCallback)(FIRAuthTokenResult *_Nullable tokenResult, + NSError *_Nullable error) + NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead."); + +/** @typedef FIRUserProfileChangeCallback + @brief The type of block called when a user profile change has finished. + + @param error Optionally; the error which occurred - or nil if the request was successful. + */ +typedef void (^FIRUserProfileChangeCallback)(NSError *_Nullable error) + NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead."); + +/** @typedef FIRSendEmailVerificationCallback + @brief The type of block called when a request to send an email verification has finished. + + @param error Optionally; the error which occurred - or nil if the request was successful. + */ +typedef void (^FIRSendEmailVerificationCallback)(NSError *_Nullable error) + NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead."); + +NS_ASSUME_NONNULL_END diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FirebaseAuth.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FirebaseAuth.h index 6f12b67291b..3917dd8e434 100644 --- a/FirebaseAuth/Sources/Public/FirebaseAuth/FirebaseAuth.h +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FirebaseAuth.h @@ -16,6 +16,14 @@ #import -// TODO: restore other headers with typedefs and string constants for CocoaPods. #import "FIRAuth.h" +#import "FIRAuthErrors.h" +#import "FIREmailAuthProvider.h" +#import "FIRFacebookAuthProvider.h" +#import "FIRFederatedAuthProvider.h" +#import "FIRGameCenterAuthProvider.h" +#import "FIRGitHubAuthProvider.h" +#import "FIRGoogleAuthProvider.h" #import "FIRMultiFactor.h" +#import "FIRPhoneAuthProvider.h" +#import "FIRTwitterAuthProvider.h" diff --git a/FirebaseAuth/Sources/Swift/Auth/Auth.swift b/FirebaseAuth/Sources/Swift/Auth/Auth.swift index e6d47d7406e..0807a4e0104 100644 --- a/FirebaseAuth/Sources/Swift/Auth/Auth.swift +++ b/FirebaseAuth/Sources/Swift/Auth/Auth.swift @@ -29,6 +29,11 @@ import FirebaseCoreExtension import UIKit #endif +// Export the deprecated Objective-C defined globals and typedefs. +#if SWIFT_PACKAGE + @_exported import FirebaseAuthInternal +#endif // SWIFT_PACKAGE + #if os(iOS) @available(iOS 13.0, *) extension Auth: UISceneDelegate { diff --git a/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift b/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift index 2a17b8fe87d..cb9e3b85e7a 100644 --- a/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift +++ b/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift @@ -38,14 +38,9 @@ private let kFIRAuthErrorMessageMalformedJWT = @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) class AuthErrorUtils: NSObject { - static let errorDomain = "FIRAuthErrorDomain" static let internalErrorDomain = "FIRAuthInternalErrorDomain" static let userInfoDeserializedResponseKey = "FIRAuthErrorUserInfoDeserializedResponseKey" static let userInfoDataKey = "FIRAuthErrorUserInfoDataKey" - static let userInfoEmailKey = "FIRAuthErrorUserInfoEmailKey" - static let userInfoUpdatedCredentialKey = "FIRAuthErrorUserInfoUpdatedCredentialKey" - static let userInfoNameKey = "FIRAuthErrorUserInfoNameKey" - static let userInfoMultiFactorResolverKey = "FIRAuthErrorUserInfoMultiFactorResolverKey" /** @var kServerErrorDetailMarker @brief This marker indicates that the server error message contains a detail error message which @@ -64,9 +59,9 @@ class AuthErrorUtils: NSObject { localizedDescription == "" { errorUserInfo[NSLocalizedDescriptionKey] = publicCode.errorDescription } - errorUserInfo[userInfoNameKey] = publicCode.errorCodeString + errorUserInfo[AuthErrors.userInfoNameKey] = publicCode.errorCodeString return NSError( - domain: errorDomain, + domain: AuthErrors.domain, code: publicCode.rawValue, userInfo: errorUserInfo ) @@ -303,7 +298,7 @@ class AuthErrorUtils: NSObject { static func emailAlreadyInUseError(email: String?) -> Error { var userInfo: [String: Any]? if let email, !email.isEmpty { - userInfo = [userInfoEmailKey: email] + userInfo = [AuthErrors.userInfoEmailKey: email] } return error(code: .emailAlreadyInUse, userInfo: userInfo) } @@ -313,10 +308,10 @@ class AuthErrorUtils: NSObject { email: String?) -> Error { var userInfo: [String: Any] = [:] if let credential { - userInfo[userInfoUpdatedCredentialKey] = credential + userInfo[AuthErrors.userInfoUpdatedCredentialKey] = credential } if let email, !email.isEmpty { - userInfo[userInfoEmailKey] = email + userInfo[AuthErrors.userInfoEmailKey] = email } if !userInfo.isEmpty { return error(code: .credentialAlreadyInUse, userInfo: userInfo) @@ -510,10 +505,10 @@ class AuthErrorUtils: NSObject { -> Error { var userInfo: [String: Any] = [:] if let email { - userInfo[userInfoEmailKey] = email + userInfo[AuthErrors.userInfoEmailKey] = email } if let updatedCredential { - userInfo[userInfoUpdatedCredentialKey] = updatedCredential + userInfo[AuthErrors.userInfoUpdatedCredentialKey] = updatedCredential } return error(code: .accountExistsWithDifferentCredential, userInfo: userInfo) } @@ -548,7 +543,7 @@ class AuthErrorUtils: NSObject { var userInfo: [String: Any] = [:] if let pendingCredential = pendingCredential, let hints = hints { let resolver = MultiFactorResolver(with: pendingCredential, hints: hints, auth: auth) - userInfo[userInfoMultiFactorResolverKey] = resolver + userInfo[AuthErrors.userInfoMultiFactorResolverKey] = resolver } return error(code: .secondFactorRequired, userInfo: userInfo) diff --git a/FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.h b/FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.h deleted file mode 100644 index 81a9db74977..00000000000 --- a/FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION) -#import - -#import "FirebaseAuth/Sources/Backend/FIRIdentityToolkitRequest.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface FIRAuthRecaptchaConfig : NSObject - -@property(nonatomic, nonnull, copy) NSString *siteKey; - -@property(nonatomic, nonnull, strong) NSDictionary *enablementStatus; - -@end - -typedef void (^FIRAuthRecaptchaTokenCallback)(NSString *_Nullable token, NSError *_Nullable error); - -typedef void (^FIRAuthRecaptchaConfigCallback)(NSError *_Nullable error); - -typedef void (^FIRAuthInjectRequestCallback)(FIRIdentityToolkitRequest *request); - -typedef NS_ENUM(NSInteger, FIRAuthRecaptchaProvider) { - FIRAuthRecaptchaProviderPassword, -}; - -typedef NS_ENUM(NSInteger, FIRAuthRecaptchaAction) { - FIRAuthRecaptchaActionDefault, - FIRAuthRecaptchaActionSignInWithPassword, - FIRAuthRecaptchaActionGetOobCode, - FIRAuthRecaptchaActionSignUpPassword -}; - -@interface FIRAuthRecaptchaVerifier : NSObject - -@property(nonatomic, weak, nullable) FIRAuth *auth; - -@property(nonatomic, strong, nullable) FIRAuthRecaptchaConfig *agentConfig; - -@property(nonatomic, strong, nullable) - NSMutableDictionary *tenantConfigs; - -@property(nonatomic, strong) id recaptchaClient; - -- (void)verifyForceRefresh:(BOOL)forceRefresh - action:(FIRAuthRecaptchaAction)action - completion:(nullable FIRAuthRecaptchaTokenCallback)completion; - -- (void)injectRecaptchaFields:(FIRIdentityToolkitRequest *)request - provider:(FIRAuthRecaptchaProvider)provider - action:(FIRAuthRecaptchaAction)action - completion:(nullable FIRAuthInjectRequestCallback)completion; - -- (BOOL)enablementStatusForProvider:(FIRAuthRecaptchaProvider)provider; - -+ (id)sharedRecaptchaVerifier:(nullable FIRAuth *)auth; - -@end - -NS_ASSUME_NONNULL_END - -#endif diff --git a/FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.m b/FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.m deleted file mode 100644 index 9587b39f4e9..00000000000 --- a/FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.m +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.h" - -#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION) - -#import "FirebaseAuth/Sources/Auth/FIRAuth_Internal.h" -#import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h" -#import "FirebaseAuth/Sources/Backend/RPC/FIRGetRecaptchaConfigRequest.h" -#import "FirebaseAuth/Sources/Backend/RPC/FIRGetRecaptchaConfigResponse.h" -#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyPasswordRequest.h" -#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h" -#import "FirebaseAuth/Sources/Utilities/FIRAuthErrorUtils.h" - -#import -#import - -static const NSDictionary *providerToStringMap; -static const NSDictionary *actionToStringMap; - -static NSString *const kClientType = @"CLIENT_TYPE_IOS"; -static NSString *const kRecaptchaVersion = @"RECAPTCHA_ENTERPRISE"; -static NSString *const kFakeToken = @"NO_RECAPTCHA"; - -@implementation FIRAuthRecaptchaConfig - -@end - -@implementation FIRAuthRecaptchaVerifier - -+ (id)sharedRecaptchaVerifier:(nullable FIRAuth *)auth { - static FIRAuthRecaptchaVerifier *sharedRecaptchaVerifier = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - sharedRecaptchaVerifier = [[self alloc] init]; - - providerToStringMap = @{@(FIRAuthRecaptchaProviderPassword) : @"EMAIL_PASSWORD_PROVIDER"}; - - actionToStringMap = @{ - @(FIRAuthRecaptchaActionSignInWithPassword) : @"signInWithPassword", - @(FIRAuthRecaptchaActionGetOobCode) : @"getOobCode", - @(FIRAuthRecaptchaActionSignUpPassword) : @"signUpPassword" - }; - }); - if (sharedRecaptchaVerifier.auth != auth) { - sharedRecaptchaVerifier.agentConfig = nil; - sharedRecaptchaVerifier.tenantConfigs = nil; - sharedRecaptchaVerifier.auth = auth; - } - return sharedRecaptchaVerifier; -} - -- (NSString *)siteKey { - if (self.auth.tenantID == nil) { - return self->_agentConfig.siteKey; - } else { - FIRAuthRecaptchaConfig *config = self->_tenantConfigs[self.auth.tenantID]; - if (config) { - return config.siteKey; - } else { - return nil; - } - } -} - -- (BOOL)enablementStatusForProvider:(FIRAuthRecaptchaProvider)provider { - if (self.auth.tenantID == nil) { - return [self->_agentConfig.enablementStatus[providerToStringMap[@(provider)]] boolValue]; - } else { - return - [self->_tenantConfigs[self.auth.tenantID].enablementStatus[providerToStringMap[@(provider)]] - boolValue]; - } -} - -- (void)verifyForceRefresh:(BOOL)forceRefresh - action:(FIRAuthRecaptchaAction)action - completion:(nullable FIRAuthRecaptchaTokenCallback)completion { - [self - retrieveRecaptchaConfigForceRefresh:forceRefresh - completion:^(NSError *_Nullable error) { - if (error) { - completion(nil, error); - } - if (!self.recaptchaClient) { - NSString *siteKey = [self siteKey]; - Class RecaptchaClass = NSClassFromString(@"Recaptcha"); - if (RecaptchaClass) { - SEL selector = - NSSelectorFromString(@"getClientWithSiteKey:completion:"); - if ([RecaptchaClass respondsToSelector:selector]) { - void (*funcWithoutTimeout)( - id, SEL, NSString *, - void (^)( - id _Nullable recaptchaClient, - NSError *_Nullable error)) = - (void *)[RecaptchaClass methodForSelector:selector]; - funcWithoutTimeout( - RecaptchaClass, selector, siteKey, - ^(id _Nullable recaptchaClient, - NSError *_Nullable error) { - if (recaptchaClient) { - self.recaptchaClient = recaptchaClient; - [self retrieveRecaptchaTokenWithAction:action - completion:completion]; - } else if (error) { - completion(nil, error); - } - }); - } else { - NSLog(@"reCAPTCHA verification faled because reCAPTCHA SDK " - @"not linked."); - completion(nil, - [FIRAuthErrorUtils recaptchaSDKNotLinkedError]); - } - } else { - NSLog(@"reCAPTCHA verification faled because reCAPTCHA SDK " - @"not linked."); - completion(nil, - [FIRAuthErrorUtils recaptchaSDKNotLinkedError]); - } - } else { - NSLog(@"reCAPTCHA verification succeeded."); - [self retrieveRecaptchaTokenWithAction:action - completion:completion]; - } - }]; -} - -- (void)retrieveRecaptchaConfigForceRefresh:(BOOL)forceRefresh - completion:(nullable FIRAuthRecaptchaConfigCallback)completion { - if (!forceRefresh) { - if (self.auth.tenantID == nil && _agentConfig != nil) { - completion(nil); - return; - } - if (self.auth.tenantID != nil && _tenantConfigs[self.auth.tenantID] != nil) { - completion(nil); - return; - } - } - FIRGetRecaptchaConfigRequest *request = [[FIRGetRecaptchaConfigRequest alloc] - initWithRequestConfiguration:self.auth.requestConfiguration]; - [FIRAuthBackend - getRecaptchaConfig:request - callback:^(FIRGetRecaptchaConfigResponse *_Nullable response, - NSError *_Nullable error) { - if (error) { - NSLog(@"reCAPTCHA config retrieval failed."); - completion(error); - } - NSLog(@"reCAPTCHA config retrieval succeeded."); - FIRAuthRecaptchaConfig *config = [[FIRAuthRecaptchaConfig alloc] init]; - // Response's site key is of the format projects//keys/' - config.siteKey = [response.recaptchaKey componentsSeparatedByString:@"/"][3]; - NSMutableDictionary *tmpEnablementStatus = [NSMutableDictionary dictionary]; - for (NSDictionary *state in response.enforcementState) { - if ([state[@"provider"] - isEqualToString:providerToStringMap[ - @(FIRAuthRecaptchaProviderPassword)]]) { - if ([state[@"enforcementState"] isEqualToString:@"ENFORCE"]) { - tmpEnablementStatus[state[@"provider"]] = @YES; - } else if ([state[@"enforcementState"] isEqualToString:@"AUDIT"]) { - tmpEnablementStatus[state[@"provider"]] = @YES; - } else if ([state[@"enforcementState"] isEqualToString:@"OFF"]) { - tmpEnablementStatus[state[@"provider"]] = @NO; - } - } - } - config.enablementStatus = tmpEnablementStatus; - - if (self.auth.tenantID == nil) { - self->_agentConfig = config; - completion(nil); - return; - } else { - if (!self->_tenantConfigs) { - self->_tenantConfigs = [[NSMutableDictionary alloc] init]; - } - self->_tenantConfigs[self.auth.tenantID] = config; - completion(nil); - return; - } - }]; -} - -- (void)retrieveRecaptchaTokenWithAction:(FIRAuthRecaptchaAction)action - completion:(nullable FIRAuthRecaptchaTokenCallback)completion { - Class RecaptchaActionClass = NSClassFromString(@"RecaptchaAction"); - if (RecaptchaActionClass) { - SEL customActionSelector = NSSelectorFromString(@"initWithCustomAction:"); - - if ([RecaptchaActionClass instancesRespondToSelector:customActionSelector]) { - // Initialize with a custom action - id (*funcWithCustomAction)(id, SEL, NSString *) = - (id(*)(id, SEL, - NSString *))[RecaptchaActionClass instanceMethodForSelector:customActionSelector]; - - id customAction = funcWithCustomAction( - [[RecaptchaActionClass alloc] init], customActionSelector, actionToStringMap[@(action)]); - - if (customAction) { - [self.recaptchaClient - execute:customAction - completion:^(NSString *_Nullable token, NSError *_Nullable error) { - if (!error) { - NSLog(@"reCAPTCHA token retrieval succeeded."); - completion(token, nil); - return; - } else { - NSLog(@"reCAPTCHA token retrieval failed. NO_RECAPTCHA sent as the fake code."); - completion(kFakeToken, nil); - } - }]; - } - } else { - completion(nil, [FIRAuthErrorUtils recaptchaSDKNotLinkedError]); - } - } else { - completion(nil, [FIRAuthErrorUtils recaptchaSDKNotLinkedError]); - } -} - -- (void)injectRecaptchaFields:(FIRIdentityToolkitRequest *)request - provider:(FIRAuthRecaptchaProvider)provider - action:(FIRAuthRecaptchaAction)action - completion:(nullable FIRAuthInjectRequestCallback)completion { - [self retrieveRecaptchaConfigForceRefresh:false - completion:^(NSError *_Nullable error) { - if ([self enablementStatusForProvider:provider]) { - [self verifyForceRefresh:false - action:action - completion:^(NSString *_Nullable token, - NSError *_Nullable error) { - [request - injectRecaptchaFields:token - recaptchaVersion:kRecaptchaVersion]; - completion(request); - }]; - } else { - [request injectRecaptchaFields:nil - recaptchaVersion:kRecaptchaVersion]; - completion(request); - } - }]; -} - -@end - -#endif diff --git a/FirebaseAuth/Tests/Unit/ObjCGlobalTests.m b/FirebaseAuth/Tests/Unit/ObjCGlobalTests.m new file mode 100644 index 00000000000..59fe0718b5e --- /dev/null +++ b/FirebaseAuth/Tests/Unit/ObjCGlobalTests.m @@ -0,0 +1,51 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +@import FirebaseAuth; + +@interface ObjCAPIGlobalTests : XCTestCase +@end + +@implementation ObjCAPIGlobalTests + +- (void)GlobalSymbolBuildTest { + __unused NSNotificationName n = FIRAuthStateDidChangeNotification; + NSString *s = FIRAuthErrorDomain; + s = FIRAuthErrorUserInfoNameKey; + s = FIRAuthErrorUserInfoEmailKey; + s = FIRAuthErrorUserInfoUpdatedCredentialKey; + s = FIRAuthErrorUserInfoMultiFactorResolverKey; + s = FIREmailAuthProviderID; + s = FIREmailLinkAuthSignInMethod; + s = FIREmailPasswordAuthSignInMethod; + s = FIRFacebookAuthProviderID; + s = FIRFacebookAuthSignInMethod; + s = FIRGameCenterAuthProviderID; + s = FIRGameCenterAuthSignInMethod; + s = FIRGitHubAuthProviderID; + s = FIRGitHubAuthSignInMethod; + s = FIRGoogleAuthProviderID; + s = FIRGoogleAuthSignInMethod; +#if TARGET_OS_IOS + s = FIRPhoneMultiFactorID; + s = FIRTOTPMultiFactorID; + s = FIRPhoneAuthProviderID; + s = FIRPhoneAuthSignInMethod; +#endif + s = FIRTwitterAuthProviderID; + s = FIRTwitterAuthSignInMethod; +} +@end diff --git a/FirebaseAuth/Tests/Unit/SwiftGlobalTests.swift b/FirebaseAuth/Tests/Unit/SwiftGlobalTests.swift new file mode 100644 index 00000000000..0d74f4dd26f --- /dev/null +++ b/FirebaseAuth/Tests/Unit/SwiftGlobalTests.swift @@ -0,0 +1,50 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +import XCTest + +import FirebaseAuth + +/// Tests globals defined in Objective C sources. These globals are for backward compatibility and +/// should not be used in new code. +class SwiftGlobalTests: XCTestCase { + func GlobalSymbolBuildTest() { + let _ = NSNotification.Name.AuthStateDidChange + let _: String = AuthErrorDomain + let _: String = AuthErrorUserInfoNameKey + let _: String = AuthErrorUserInfoEmailKey + let _: String = AuthErrorUserInfoUpdatedCredentialKey + let _: String = AuthErrorUserInfoMultiFactorResolverKey + let _: String = EmailAuthProviderID + let _: String = EmailLinkAuthSignInMethod + let _: String = EmailPasswordAuthSignInMethod + let _: String = FacebookAuthProviderID + let _: String = FacebookAuthSignInMethod + let _: String = GameCenterAuthProviderID + let _: String = GameCenterAuthSignInMethod + let _: String = GitHubAuthProviderID + let _: String = GitHubAuthSignInMethod + let _: String = GoogleAuthProviderID + let _: String = GoogleAuthSignInMethod + #if os(iOS) + let _: String = PhoneMultiFactorID + let _: String = TOTPMultiFactorID + let _: String = PhoneAuthProviderID + let _: String = PhoneAuthSignInMethod + #endif + let _: String = TwitterAuthProviderID + let _: String = TwitterAuthSignInMethod + } +} diff --git a/FirebaseAuth/Tests/UnitObjC/ObjCAPITests.m b/FirebaseAuth/Tests/UnitObjC/ObjCAPITests.m deleted file mode 100644 index 5f88074b789..00000000000 --- a/FirebaseAuth/Tests/UnitObjC/ObjCAPITests.m +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// TODO: Add Objective C API tests here after verifying in v10 - -#import diff --git a/Package.swift b/Package.swift index a0cbd3eb287..94cbdfb973c 100644 --- a/Package.swift +++ b/Package.swift @@ -425,6 +425,7 @@ let package = Package( dependencies: [ "FirebaseAppCheckInterop", "FirebaseAuthInterop", + "FirebaseAuthInternal", "FirebaseCore", "FirebaseCoreExtension", .product(name: "GULAppDelegateSwizzler", package: "GoogleUtilities"), @@ -438,6 +439,17 @@ let package = Package( .linkedFramework("SafariServices", .when(platforms: [.iOS])), ] ), + .target( + name: "FirebaseAuthInternal", + path: "FirebaseAuth/Sources", + exclude: [ + "Swift", + ], + publicHeadersPath: "Public", + cSettings: [ + .headerSearchPath("../../"), + ] + ), // Internal headers only for consuming from Swift. .target( name: "FirebaseAuthInterop", @@ -461,6 +473,7 @@ let package = Package( "PhoneAuthProviderTests.swift", "AuthNotificationManagerTests.swift", "ObjCAPITests.m", // Only builds via CocoaPods until mixed language or its own target. + "ObjCGlobalTests.m", // Only builds via CocoaPods until mixed language or its own target. ] ), .target(