diff options
author | 2017-06-02 18:42:17 +0100 | |
---|---|---|
committer | 2017-06-02 10:42:17 -0700 | |
commit | 5c59342e6e19989c012877362af529b3d5d0abeb (patch) | |
tree | 457f5da7c41ee45b8d3f55f83017fff2ab718781 /Firebase/Auth/Source | |
parent | 6f700dd6c81711a8605c2587b4f2acfd4e07466b (diff) |
macOS (#38)
* Example/Core: create macOS app/tests target
* Example/Core: Core_Example/Tests -> Core_Example/Tests_iOS
* Example/Core: macOS building/tests passing
* Example/Database: separate iOS/macOS targets
* BuildFrameworks: macOS
* .travis.yml, test.sh: AllUnitTests -> AllUnitTests_iOS
* test.sh: add AllUnitTests_macOS
* Example/Storage: Example/Tests->_iOS
* Example/Storage: macOS
* test.sh: try to prevent double error 65
* test.sh: build before test
* Example/Auth|Messaging: -> _iOS
* Example/Auth: macOS build
* Example/Auth: macOS passing
* Example/Firebase: pod de/re-integrate; fix static DerivedData references; copy phase for OCMock
* Example/Firebase: manually copied OCMock, Products Dir vs. Frameworks
* Example/Firebase: copied OCMock, prevent header removal
* Example/Storage: integration tests sdk fix
* Example/Auth: macOS exclude FIRAuthAppCredentialManager; cleanup
* Firebase/Core: remove nullability annotation
* Firebase/Core|Database: correct TARGET_X usage for correctness and anticipation of OS_WATCH|TV branches
* build.swift: style fix
* Firebase/Core: FIRLogger: fix macOS intermittent va_list error
Diffstat (limited to 'Firebase/Auth/Source')
-rw-r--r-- | Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthCredential.m | 1 | ||||
-rw-r--r-- | Firebase/Auth/Source/FIRAuth.h | 9 | ||||
-rw-r--r-- | Firebase/Auth/Source/FIRAuth.m | 37 | ||||
-rw-r--r-- | Firebase/Auth/Source/FIRUser.h | 2 | ||||
-rw-r--r-- | Firebase/Auth/Source/FIRUser.m | 11 | ||||
-rw-r--r-- | Firebase/Auth/Source/Private/FIRAuth_Internal.h | 4 | ||||
-rw-r--r-- | Firebase/Auth/Source/RPCs/FIRAuthBackend.h | 4 | ||||
-rw-r--r-- | Firebase/Auth/Source/RPCs/FIRAuthBackend.m | 9 |
8 files changed, 67 insertions, 10 deletions
diff --git a/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthCredential.m b/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthCredential.m index b9bf577..c7e8bb1 100644 --- a/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthCredential.m +++ b/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthCredential.m @@ -16,7 +16,6 @@ #import "FIRPhoneAuthCredential.h" -#import "FIRPhoneAuthProvider.h" #import "FIRPhoneAuthCredential_Internal.h" #import "FIRAuthCredential_Internal.h" #import "FIRAuthExceptionUtils.h" diff --git a/Firebase/Auth/Source/FIRAuth.h b/Firebase/Auth/Source/FIRAuth.h index 6e59e86..65b55d6 100644 --- a/Firebase/Auth/Source/FIRAuth.h +++ b/Firebase/Auth/Source/FIRAuth.h @@ -16,10 +16,13 @@ #import <Foundation/Foundation.h> -#import "FIRAuthAPNSTokenType.h" #import "FIRAuthErrors.h" #import "FIRAuthSwiftNameSupport.h" +#if TARGET_OS_IOS +#import "FIRAuthAPNSTokenType.h" +#endif + @class FIRApp; @class FIRAuth; @class FIRAuthCredential; @@ -249,6 +252,7 @@ FIR_SWIFT_NAME(Auth) */ @property(nonatomic, strong, readonly, nullable) FIRUser *currentUser; +#if TARGET_OS_IOS /** @property APNSToken @brief The APNs token used for phone number authentication. The type of the token (production or sandbox) will be attempted to be automatcially detected. @@ -256,6 +260,7 @@ FIR_SWIFT_NAME(Auth) by either setting this property or by calling @c setAPNSToken:type: */ @property(nonatomic, strong, nullable) NSData *APNSToken; +#endif /** @fn init @brief Please access auth instances using @c FIRAuth.auth and @c FIRAuth.authForApp:. @@ -587,6 +592,7 @@ FIR_SWIFT_NAME(Auth) */ - (void)removeIDTokenDidChangeListener:(FIRIDTokenDidChangeListenerHandle)listenerHandle; +#if TARGET_OS_IOS /** @fn setAPNSToken:type: @brief Sets the APNs token along with its type. @remarks If swizzling is disabled, the APNs Token must be set for phone number auth to work, @@ -606,6 +612,7 @@ FIR_SWIFT_NAME(Auth) for phone number auth to work. */ - (BOOL)canHandleNotification:(NSDictionary *)userInfo; +#endif @end diff --git a/Firebase/Auth/Source/FIRAuth.m b/Firebase/Auth/Source/FIRAuth.m index 5b1da8c..dca0c1d 100644 --- a/Firebase/Auth/Source/FIRAuth.m +++ b/Firebase/Auth/Source/FIRAuth.m @@ -23,10 +23,6 @@ #import "AuthProviders/EmailPassword/FIREmailPasswordAuthCredential.h" #import "AuthProviders/Phone/FIRPhoneAuthCredential_Internal.h" #import "Private/FIRAdditionalUserInfo_Internal.h" -#import "Private/FIRAuthAPNSToken.h" -#import "Private/FIRAuthAPNSTokenManager.h" -#import "Private/FIRAuthAppCredentialManager.h" -#import "Private/FIRAuthAppDelegateProxy.h" #import "Private/FIRAuthCredential_Internal.h" #import "Private/FIRAuthDataResult_Internal.h" #import "Private/FIRAuthDispatcher.h" @@ -34,7 +30,6 @@ #import "FIRAuthExceptionUtils.h" #import "Private/FIRAuthGlobalWorkQueue.h" #import "Private/FIRAuthKeychain.h" -#import "Private/FIRAuthNotificationManager.h" #import "Private/FIRUser_Internal.h" #import "FirebaseAuth.h" #import "FIRAuthBackend.h" @@ -59,6 +54,14 @@ #import "FIRVerifyPhoneNumberRequest.h" #import "FIRVerifyPhoneNumberResponse.h" +#if TARGET_OS_IOS +#import "Private/FIRAuthAPNSToken.h" +#import "Private/FIRAuthAPNSTokenManager.h" +#import "Private/FIRAuthAppCredentialManager.h" +#import "Private/FIRAuthAppDelegateProxy.h" +#import "Private/FIRAuthNotificationManager.h" +#endif + #pragma mark - Constants NSString *const FIRAuthStateDidChangeInternalNotification = @@ -173,7 +176,11 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; #pragma mark - FIRAuth +#if TARGET_OS_IOS @interface FIRAuth () <FIRAuthAppDelegateHandler> +#else +@interface FIRAuth () +#endif /** @property firebaseAppId @brief The Firebase app ID. @@ -309,6 +316,8 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; FIRLogInfo(kFIRLoggerAuth, @"I-AUT000002", @"Token auto-refresh enabled."); strongSelf->_autoRefreshTokens = YES; [strongSelf scheduleAutoTokenRefresh]; + + #if TARGET_OS_IOS // TODO: Is a similar mechanism needed on macOS? strongSelf->_applicationDidBecomeActiveObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil @@ -332,6 +341,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; strongSelf->_isAppInBackground = YES; } }]; + #endif } if (!strongSelf.currentUser) { dispatch_async(dispatch_get_main_queue(), ^{ @@ -378,14 +388,20 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; FIRLogError(kFIRLoggerAuth, @"I-AUT000001", @"Error loading saved user when starting up: %@", error); } + + #if TARGET_OS_IOS // Initialize for phone number auth. _tokenManager = [[FIRAuthAPNSTokenManager alloc] initWithApplication:[UIApplication sharedApplication]]; + _appCredentialManager = [[FIRAuthAppCredentialManager alloc] initWithKeychain:_keychain]; + _notificationManager = [[FIRAuthNotificationManager alloc] initWithApplication:[UIApplication sharedApplication] appCredentialManager:_appCredentialManager]; + [[FIRAuthAppDelegateProxy sharedInstance] addHandler:self]; + #endif } return self; } @@ -398,12 +414,15 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; [defaultCenter removeObserver:handleToRemove]; [_listenerHandles removeLastObject]; } + + #if TARGET_OS_IOS [defaultCenter removeObserver:_applicationDidBecomeActiveObserver name:UIApplicationDidBecomeActiveNotification object:nil]; [defaultCenter removeObserver:_applicationDidEnterBackgroundObserver name:UIApplicationDidEnterBackgroundNotification object:nil]; + #endif } } @@ -520,6 +539,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; return; } + #if TARGET_OS_IOS if ([credential isKindOfClass:[FIRPhoneAuthCredential class]]) { // Special case for phone auth credential FIRPhoneAuthCredential *phoneCredential = (FIRPhoneAuthCredential *)credential; @@ -533,6 +553,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; }]; return; } + #endif FIRVerifyAssertionRequest *request = [[FIRVerifyAssertionRequest alloc] initWithAPIKey:_APIKey providerID:credential.provider]; @@ -839,7 +860,8 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; } } -- (NSData *)APNStoken { +#if TARGET_OS_IOS +- (NSData *)APNSToken { __block NSData *result = nil; dispatch_sync(FIRAuthGlobalWorkQueue(), ^{ result = _tokenManager.token.data; @@ -864,9 +886,11 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; }); return result; } +#endif #pragma mark - Internal Methods +#if TARGET_OS_IOS /** @fn signInWithPhoneCredential:callback: @brief Signs in using a phone credential. @param credential The Phone Auth credential used to sign in. @@ -922,6 +946,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; callback:callback]; }]; } +#endif - (void)notifyListenersOfAuthStateChangeWithUser:(FIRUser *)user token:(NSString *)token { if (user && _autoRefreshTokens) { diff --git a/Firebase/Auth/Source/FIRUser.h b/Firebase/Auth/Source/FIRUser.h index ebe8b81..9e3ac77 100644 --- a/Firebase/Auth/Source/FIRUser.h +++ b/Firebase/Auth/Source/FIRUser.h @@ -158,6 +158,7 @@ FIR_SWIFT_NAME(User) completion:(nullable FIRUserProfileChangeCallback)completion FIR_SWIFT_NAME(updatePassword(to:completion:)); +#if TARGET_OS_IOS /** @fn updatePhoneNumberCredential:completion: @brief Updates the phone number for the user. On success, the cached user profile data is updated. @@ -181,6 +182,7 @@ FIR_SWIFT_NAME(User) */ - (void)updatePhoneNumberCredential:(FIRPhoneAuthCredential *)phoneNumberCredential completion:(nullable FIRUserProfileChangeCallback)completion; +#endif /** @fn profileChangeRequest @brief Creates an object which may be used to change the user's profile data. diff --git a/Firebase/Auth/Source/FIRUser.m b/Firebase/Auth/Source/FIRUser.m index f0c3226..c45539c 100644 --- a/Firebase/Auth/Source/FIRUser.m +++ b/Firebase/Auth/Source/FIRUser.m @@ -19,7 +19,6 @@ #import "AuthProviders/EmailPassword/FIREmailPasswordAuthCredential.h" #import "AuthProviders/EmailPassword/FIREmailAuthProvider.h" #import "AuthProviders/Phone/FIRPhoneAuthCredential_Internal.h" -#import "AuthProviders/Phone/FIRPhoneAuthProvider.h" #import "Private/FIRAdditionalUserInfo_Internal.h" #import "FIRAuth.h" #import "Private/FIRAuthCredential_Internal.h" @@ -48,6 +47,10 @@ #import "FIRVerifyPhoneNumberRequest.h" #import "FIRVerifyPhoneNumberResponse.h" +#if TARGET_OS_IOS +#import "AuthProviders/Phone/FIRPhoneAuthProvider.h" +#endif + NS_ASSUME_NONNULL_BEGIN /** @var kUserIDCodingKey @@ -602,6 +605,7 @@ static void callInMainThreadWithAuthDataResultAndError( }); } +#if TARGET_OS_IOS /** @fn internalUpdatePhoneNumberCredential:completion: @brief Updates the phone number for the user. On success, the cached user profile data is updated. @@ -654,6 +658,7 @@ static void callInMainThreadWithAuthDataResultAndError( }]; }); } +#endif - (FIRUserProfileChangeRequest *)profileChangeRequest { __block FIRUserProfileChangeRequest *result; @@ -839,6 +844,7 @@ static void callInMainThreadWithAuthDataResultAndError( return; } + #if TARGET_OS_IOS if ([credential isKindOfClass:[FIRPhoneAuthCredential class]]) { FIRPhoneAuthCredential *phoneAuthCredential = (FIRPhoneAuthCredential *)credential; [self internalUpdatePhoneNumberCredential:phoneAuthCredential @@ -851,6 +857,7 @@ static void callInMainThreadWithAuthDataResultAndError( }]; return; } + #endif [_taskQueue enqueueTask:^(FIRAuthSerialTaskCompletionBlock _Nonnull complete) { CallbackWithAuthDataResultAndError completeWithError = @@ -960,11 +967,13 @@ static void callInMainThreadWithAuthDataResultAndError( [mutableProviderData removeObjectForKey:provider]; _providerData = [mutableProviderData copy]; + #if TARGET_OS_IOS // After successfully unlinking a phone auth provider, remove the phone number from the // cached user info. if ([provider isEqualToString:FIRPhoneAuthProviderID]) { _phoneNumber = nil; } + #endif } if (response.IDToken && response.refreshToken) { FIRSecureTokenService *tokenService = diff --git a/Firebase/Auth/Source/Private/FIRAuth_Internal.h b/Firebase/Auth/Source/Private/FIRAuth_Internal.h index bdbefce..afcd899 100644 --- a/Firebase/Auth/Source/Private/FIRAuth_Internal.h +++ b/Firebase/Auth/Source/Private/FIRAuth_Internal.h @@ -16,9 +16,11 @@ #import "FIRAuth.h" +#if TARGET_OS_IOS @class FIRAuthAPNSTokenManager; @class FIRAuthAppCredentialManager; @class FIRAuthNotificationManager; +#endif NS_ASSUME_NONNULL_BEGIN @@ -46,6 +48,7 @@ extern NSString *const FIRAuthStateDidChangeInternalNotificationTokenKey; */ @property(nonatomic, copy, readonly) NSString *APIKey; +#if TARGET_OS_IOS /** @property tokenManager @brief The manager for APNs tokens used by phone number auth. */ @@ -60,6 +63,7 @@ extern NSString *const FIRAuthStateDidChangeInternalNotificationTokenKey; @brief The manager for remote notifications used by phone number auth. */ @property(nonatomic, strong, readonly) FIRAuthNotificationManager *notificationManager; +#endif /** @fn initWithAPIKey:appName: @brief Designated initializer. diff --git a/Firebase/Auth/Source/RPCs/FIRAuthBackend.h b/Firebase/Auth/Source/RPCs/FIRAuthBackend.h index 519a6e7..521cf16 100644 --- a/Firebase/Auth/Source/RPCs/FIRAuthBackend.h +++ b/Firebase/Auth/Source/RPCs/FIRAuthBackend.h @@ -312,6 +312,7 @@ typedef void (^FIRVerifyClientResponseCallback) + (void)deleteAccount:(FIRDeleteAccountRequest *)request callback:(FIRDeleteCallBack)callback; +#if TARGET_OS_IOS /** @fn sendVerificationCode:callback: @brief Calls the sendVerificationCode endpoint, which is responsible for sending the verification code to a phone number specified in the request parameters. @@ -338,6 +339,7 @@ typedef void (^FIRVerifyClientResponseCallback) */ + (void)verifyClient:(FIRVerifyClientRequest *)request callback:(FIRVerifyClientResponseCallback)callback; +#endif @end @@ -455,6 +457,7 @@ typedef void (^FIRVerifyClientResponseCallback) - (void)deleteAccount:(FIRDeleteAccountRequest *)request callback:(FIRDeleteCallBack)callback; +#if TARGET_OS_IOS /** @fn sendVerificationCode:callback: @brief Calls the sendVerificationCode endpoint, which is responsible for sending the verification code to a phone number specified in the request parameters. @@ -481,6 +484,7 @@ typedef void (^FIRVerifyClientResponseCallback) */ - (void)verifyClient:(FIRVerifyClientRequest *)request callback:(FIRVerifyClientResponseCallback)callback; +#endif /** @fn resetPassword:callback @brief Calls the resetPassword endpoint, which is responsible for resetting a user's password diff --git a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m index 3efc602..3b899f0 100644 --- a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m +++ b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m @@ -17,7 +17,6 @@ #import "FIRAuthBackend.h" #import "../AuthProviders/Phone/FIRPhoneAuthCredential_Internal.h" -#import "../AuthProviders/Phone/FIRPhoneAuthProvider.h" #import "../Private/FIRAuthErrorUtils.h" #import "../Private/FIRAuthGlobalWorkQueue.h" #import "FirebaseAuth.h" @@ -54,6 +53,10 @@ #import <GTMSessionFetcher/GTMSessionFetcher.h> #import <GTMSessionFetcher/GTMSessionFetcherService.h> +#if TARGET_OS_IOS +#import "../AuthProviders/Phone/FIRPhoneAuthProvider.h" +#endif + /** @var kIosBundleIdentifierHeader @brief HTTP header name for iOS bundle ID. */ @@ -374,6 +377,7 @@ static id<FIRAuthBackendImplementation> gBackendImplementation; [[self implementation] deleteAccount:request callback:callback]; } +#if TARGET_OS_IOS + (void)sendVerificationCode:(FIRSendVerificationCodeRequest *)request callback:(FIRSendVerificationCodeResponseCallback)callback { [[self implementation] sendVerificationCode:request callback:callback]; @@ -387,6 +391,7 @@ static id<FIRAuthBackendImplementation> gBackendImplementation; + (void)verifyClient:(id)request callback:(FIRVerifyClientResponseCallback)callback { [[self implementation] verifyClient:request callback:callback]; } +#endif + (void)resetPassword:(FIRResetPasswordRequest *)request callback:(FIRResetPasswordCallback)callback { @@ -560,6 +565,7 @@ static id<FIRAuthBackendImplementation> gBackendImplementation; [self postWithRequest:request response:response callback:callback]; } +#if TARGET_OS_IOS - (void)sendVerificationCode:(FIRSendVerificationCodeRequest *)request callback:(FIRSendVerificationCodeResponseCallback)callback { FIRSendVerificationCodeResponse *response = [[FIRSendVerificationCodeResponse alloc] init]; @@ -606,6 +612,7 @@ static id<FIRAuthBackendImplementation> gBackendImplementation; callback(response, nil); }]; } +#endif - (void)resetPassword:(FIRResetPasswordRequest *)request callback:(FIRResetPasswordCallback)callback { |