aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Database/Login/FAuthTokenProvider.m
diff options
context:
space:
mode:
Diffstat (limited to 'Firebase/Database/Login/FAuthTokenProvider.m')
-rw-r--r--Firebase/Database/Login/FAuthTokenProvider.m75
1 files changed, 10 insertions, 65 deletions
diff --git a/Firebase/Database/Login/FAuthTokenProvider.m b/Firebase/Database/Login/FAuthTokenProvider.m
index f3c2a61..8d65609 100644
--- a/Firebase/Database/Login/FAuthTokenProvider.m
+++ b/Firebase/Database/Login/FAuthTokenProvider.m
@@ -16,65 +16,22 @@
#import "FAuthTokenProvider.h"
#import "FUtilities.h"
+#import "FIRAppInternal.h"
#import "FIRLogger.h"
#import "FIRDatabaseQuery_Private.h"
#import "FIRNoopAuthTokenProvider.h"
-static NSString *const FIRAuthStateDidChangeInternalNotification = @"FIRAuthStateDidChangeInternalNotification";
-static NSString *const FIRAuthStateDidChangeInternalNotificationTokenKey = @"FIRAuthStateDidChangeInternalNotificationTokenKey";
-
-
-/**
- * This is a hack that defines all the methods we need from FIRFirebaseApp. At runtime we use reflection to get an
- * actual instance of FIRFirebaseApp. Since protocols don't carry any runtime information and selectors are invoked
- * by name we can write code against this protocol as long as the method signatures of FIRFirebaseApp don't change.
- */
-@protocol FIRFirebaseAppLike <NSObject>
-
-- (void)getTokenForcingRefresh:(BOOL)forceRefresh withCallback:(void (^)(NSString *_Nullable token, NSError *_Nullable error))callback;
-
-@end
-
-
-/**
- * This is a hack that defines all the methods we need from FIRAuth.
- */
-@protocol FIRFirebaseAuthLike <NSObject>
-
-- (id<FIRFirebaseAppLike>) app;
-
-@end
-
-/**
- * This is a hack that copies the definitions of Firebase Auth error codes. If the error codes change in the original code, this
- * will break at runtime due to undefined behavior!
- */
-typedef NS_ENUM(NSUInteger, FIRErrorCode) {
- /*! @var FIRErrorCodeNoAuth
- @brief Represents the case where an auth-related message was sent to a @c FIRFirebaseApp
- instance which has no associated @c FIRAuth instance.
- */
- FIRErrorCodeNoAuth,
-
- /*! @var FIRErrorCodeNoSignedInUser
- @brief Represents the case where an attempt was made to fetch a token when there is no signed
- in user.
- */
- FIRErrorCodeNoSignedInUser,
-};
-
-
@interface FAuthStateListenerWrapper : NSObject
@property (nonatomic, copy) fbt_void_nsstring listener;
-@property (nonatomic, weak) id<FIRFirebaseAppLike> app;
+@property (nonatomic, weak) FIRApp *app;
@end
@implementation FAuthStateListenerWrapper
-- (instancetype) initWithListener:(fbt_void_nsstring)listener app:(id<FIRFirebaseAppLike>)app {
+- (instancetype) initWithListener:(fbt_void_nsstring)listener app:(FIRApp *)app {
self = [super init];
if (self != nil) {
self->_listener = listener;
@@ -88,9 +45,9 @@ typedef NS_ENUM(NSUInteger, FIRErrorCode) {
}
- (void) authStateDidChangeNotification:(NSNotification *)notification {
- id<FIRFirebaseAuthLike> auth = notification.object;
- if (auth.app == self->_app) {
- NSDictionary *userInfo = notification.userInfo;
+ NSDictionary *userInfo = notification.userInfo;
+ FIRApp *authApp = userInfo[FIRAuthStateDidChangeInternalNotificationAppKey];
+ if (authApp == self.app) {
NSString *token = userInfo[FIRAuthStateDidChangeInternalNotificationTokenKey];
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
self.listener(token);
@@ -107,17 +64,17 @@ typedef NS_ENUM(NSUInteger, FIRErrorCode) {
@interface FIRFirebaseAuthTokenProvider : NSObject <FAuthTokenProvider>
-@property (nonatomic, strong) id<FIRFirebaseAppLike> app;
+@property (nonatomic, strong) FIRApp *app;
/** Strong references to the auth listeners as they are only weak in FIRFirebaseApp */
@property (nonatomic, strong) NSMutableArray *authListeners;
-- (instancetype) initWithFirebaseApp:(id<FIRFirebaseAppLike>)app;
+- (instancetype) initWithFirebaseApp:(FIRApp *)app;
@end
@implementation FIRFirebaseAuthTokenProvider
-- (instancetype) initWithFirebaseApp:(id<FIRFirebaseAppLike>)app {
+- (instancetype) initWithFirebaseApp:(FIRApp *)app {
self = [super init];
if (self != nil) {
self->_app = app;
@@ -130,19 +87,7 @@ typedef NS_ENUM(NSUInteger, FIRErrorCode) {
// TODO: Don't fetch token if there is no current user
[self.app getTokenForcingRefresh:forceRefresh withCallback:^(NSString * _Nullable token, NSError * _Nullable error) {
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
- if (error != nil) {
- if (error.code == FIRErrorCodeNoAuth) {
- FFLog(@"I-RDB073001", @"Firebase Auth is not configured, not going to use authentication.");
- callback(nil, nil);
- } else if (error.code == FIRErrorCodeNoSignedInUser) {
- // No signed in user is an expected case, callback as success with no token
- callback(nil, nil);
- } else {
- callback(nil, error);
- }
- } else {
- callback(token, nil);
- }
+ callback(token, error);
});
}];
}