aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Auth/Source/FIRAuth.m
diff options
context:
space:
mode:
Diffstat (limited to 'Firebase/Auth/Source/FIRAuth.m')
-rw-r--r--Firebase/Auth/Source/FIRAuth.m37
1 files changed, 31 insertions, 6 deletions
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) {