aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Auth
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/Source/Auth')
-rw-r--r--Firestore/Source/Auth/FSTCredentialsProvider.h13
-rw-r--r--Firestore/Source/Auth/FSTCredentialsProvider.mm43
-rw-r--r--Firestore/Source/Auth/FSTEmptyCredentialsProvider.mm7
-rw-r--r--Firestore/Source/Auth/FSTUser.h43
-rw-r--r--Firestore/Source/Auth/FSTUser.mm68
5 files changed, 42 insertions, 132 deletions
diff --git a/Firestore/Source/Auth/FSTCredentialsProvider.h b/Firestore/Source/Auth/FSTCredentialsProvider.h
index 92d5fdc..230a22d 100644
--- a/Firestore/Source/Auth/FSTCredentialsProvider.h
+++ b/Firestore/Source/Auth/FSTCredentialsProvider.h
@@ -16,16 +16,17 @@
#import <Foundation/Foundation.h>
+#include "Firestore/core/src/firebase/firestore/auth/user.h"
+
NS_ASSUME_NONNULL_BEGIN
@class FIRApp;
@class FSTDispatchQueue;
-@class FSTUser;
#pragma mark - FSTGetTokenResult
/**
- * The current FSTUser and the authentication token provided by the underlying authentication
+ * The current User and the authentication token provided by the underlying authentication
* mechanism. This is the result of calling -[FSTCredentialsProvider getTokenForcingRefresh].
*
* ## Portability notes: no TokenType on iOS
@@ -38,11 +39,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface FSTGetTokenResult : NSObject
- (instancetype)init NS_UNAVAILABLE;
-- (instancetype)initWithUser:(FSTUser *)user
+- (instancetype)initWithUser:(const firebase::firestore::auth::User &)user
token:(NSString *_Nullable)token NS_DESIGNATED_INITIALIZER;
/** The user with which the token is associated (used for persisting user state on disk, etc.). */
-@property(nonatomic, nonnull, readonly) FSTUser *user;
+@property(nonatomic, assign, readonly) const firebase::firestore::auth::User &user;
/** The actual raw token. */
@property(nonatomic, copy, nullable, readonly) NSString *token;
@@ -60,8 +61,8 @@ NS_ASSUME_NONNULL_BEGIN
typedef void (^FSTVoidGetTokenResultBlock)(FSTGetTokenResult *_Nullable token,
NSError *_Nullable error);
-/** Listener block notified with an FSTUser. */
-typedef void (^FSTVoidUserBlock)(FSTUser *user);
+/** Listener block notified with a User. */
+typedef void (^FSTVoidUserBlock)(const firebase::firestore::auth::User &user);
#pragma mark - FSTCredentialsProvider
diff --git a/Firestore/Source/Auth/FSTCredentialsProvider.mm b/Firestore/Source/Auth/FSTCredentialsProvider.mm
index 653d7ff..cf045e3 100644
--- a/Firestore/Source/Auth/FSTCredentialsProvider.mm
+++ b/Firestore/Source/Auth/FSTCredentialsProvider.mm
@@ -21,36 +21,53 @@
#import <GRPCClient/GRPCCall.h>
#import "FIRFirestoreErrors.h"
-#import "Firestore/Source/Auth/FSTUser.h"
#import "Firestore/Source/Util/FSTAssert.h"
#import "Firestore/Source/Util/FSTClasses.h"
#import "Firestore/Source/Util/FSTDispatchQueue.h"
+#include "Firestore/core/src/firebase/firestore/auth/user.h"
+#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
+
+namespace util = firebase::firestore::util;
+using firebase::firestore::auth::User;
+
NS_ASSUME_NONNULL_BEGIN
#pragma mark - FSTGetTokenResult
+@interface FSTGetTokenResult () {
+ User _user;
+}
+
+@end
+
@implementation FSTGetTokenResult
-- (instancetype)initWithUser:(FSTUser *)user token:(NSString *_Nullable)token {
+
+- (instancetype)initWithUser:(const User &)user token:(NSString *_Nullable)token {
if (self = [super init]) {
_user = user;
_token = token;
}
return self;
}
+
+- (const User &)user {
+ return _user;
+}
+
@end
#pragma mark - FSTFirebaseCredentialsProvider
-@interface FSTFirebaseCredentialsProvider ()
+@interface FSTFirebaseCredentialsProvider () {
+ /** The current user as reported to us via our AuthStateDidChangeListener. */
+ User _currentUser;
+}
@property(nonatomic, strong, readonly) FIRApp *app;
/** Handle used to stop receiving auth changes once userChangeListener is removed. */
@property(nonatomic, strong, nullable, readwrite) id<NSObject> authListenerHandle;
-/** The current user as reported to us via our AuthStateDidChangeListener. */
-@property(nonatomic, strong, nonnull, readwrite) FSTUser *currentUser;
-
/**
* Counter used to detect if the user changed while a -getTokenForcingRefresh: request was
* outstanding.
@@ -67,7 +84,7 @@ NS_ASSUME_NONNULL_BEGIN
self = [super init];
if (self) {
_app = app;
- _currentUser = [[FSTUser alloc] initWithUID:[self.app getUID]];
+ _currentUser = User([self.app getUID]);
_userCounter = 0;
// Register for user changes so that we can internally track the current user.
@@ -90,13 +107,13 @@ NS_ASSUME_NONNULL_BEGIN
}
NSString *userID = userInfo[FIRAuthStateDidChangeInternalNotificationUIDKey];
- FSTUser *newUser = [[FSTUser alloc] initWithUID:userID];
- if (![newUser isEqual:self.currentUser]) {
- self.currentUser = newUser;
+ User newUser = User(userID);
+ if (newUser != _currentUser) {
+ _currentUser = newUser;
self.userCounter++;
FSTVoidUserBlock listenerBlock = self.userChangeListener;
if (listenerBlock) {
- listenerBlock(self.currentUser);
+ listenerBlock(_currentUser);
}
}
}
@@ -127,7 +144,7 @@ NS_ASSUME_NONNULL_BEGIN
completion(nil, cancelError);
} else {
FSTGetTokenResult *result =
- [[FSTGetTokenResult alloc] initWithUser:self.currentUser token:token];
+ [[FSTGetTokenResult alloc] initWithUser:_currentUser token:token];
completion(result, error);
}
};
@@ -142,7 +159,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTAssert(!_userChangeListener, @"UserChangeListener set twice!");
// Fire initial event.
- block(self.currentUser);
+ block(_currentUser);
} else {
FSTAssert(self.authListenerHandle, @"UserChangeListener removed twice!");
FSTAssert(_userChangeListener, @"UserChangeListener removed without being set!");
diff --git a/Firestore/Source/Auth/FSTEmptyCredentialsProvider.mm b/Firestore/Source/Auth/FSTEmptyCredentialsProvider.mm
index e78452a..8139d79 100644
--- a/Firestore/Source/Auth/FSTEmptyCredentialsProvider.mm
+++ b/Firestore/Source/Auth/FSTEmptyCredentialsProvider.mm
@@ -16,10 +16,13 @@
#import "Firestore/Source/Auth/FSTEmptyCredentialsProvider.h"
-#import "Firestore/Source/Auth/FSTUser.h"
#import "Firestore/Source/Util/FSTAssert.h"
#import "Firestore/Source/Util/FSTDispatchQueue.h"
+#include "Firestore/core/src/firebase/firestore/auth/user.h"
+
+using firebase::firestore::auth::User;
+
NS_ASSUME_NONNULL_BEGIN
@implementation FSTEmptyCredentialsProvider
@@ -33,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
// Since the user never changes, we just need to fire the initial event and don't need to hang
// onto the block.
if (block) {
- block([FSTUser unauthenticatedUser]);
+ block(User::Unauthenticated());
}
}
diff --git a/Firestore/Source/Auth/FSTUser.h b/Firestore/Source/Auth/FSTUser.h
deleted file mode 100644
index 68ecc4c..0000000
--- a/Firestore/Source/Auth/FSTUser.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 <Foundation/Foundation.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-/**
- * Simple wrapper around a nullable UID. Mostly exists to make code more readable and for use as
- * a key in dictionaries (since keys cannot be nil).
- */
-@interface FSTUser : NSObject <NSCopying>
-
-/** Returns an FSTUser with a nil UID. */
-+ (instancetype)unauthenticatedUser;
-
-// Porting note: no GOOGLE_CREDENTIALS or FIRST_PARTY equivalent on iOS, see FSTGetTokenResult for
-// more details.
-
-/** Initializes an FSTUser with the given UID. */
-- (instancetype)initWithUID:(NSString *_Nullable)UID NS_DESIGNATED_INITIALIZER;
-- (instancetype)init NS_UNAVAILABLE;
-
-@property(nonatomic, copy, nullable, readonly) NSString *UID;
-
-@property(nonatomic, assign, readonly, getter=isUnauthenticated) BOOL unauthenticated;
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/Auth/FSTUser.mm b/Firestore/Source/Auth/FSTUser.mm
deleted file mode 100644
index 605b4e6..0000000
--- a/Firestore/Source/Auth/FSTUser.mm
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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 "Firestore/Source/Auth/FSTUser.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-#pragma mark - FSTUser
-
-@implementation FSTUser
-
-@dynamic unauthenticated;
-
-+ (instancetype)unauthenticatedUser {
- return [[FSTUser alloc] initWithUID:nil];
-}
-
-- (instancetype)initWithUID:(NSString *_Nullable)UID {
- if (self = [super init]) {
- _UID = UID;
- }
- return self;
-}
-
-- (BOOL)isEqual:(id)object {
- if (self == object) {
- return YES;
- } else if (![object isKindOfClass:[FSTUser class]]) {
- return NO;
- } else {
- FSTUser *other = object;
- return (self.isUnauthenticated && other.isUnauthenticated) ||
- [self.UID isEqualToString:other.UID];
- }
-}
-
-- (NSUInteger)hash {
- return [self.UID hash];
-}
-
-- (id)copyWithZone:(nullable NSZone *)zone {
- return self; // since FSTUser objects are immutable
-}
-
-- (NSString *)description {
- return [NSString stringWithFormat:@"<FSTUser uid=%@>", self.UID];
-}
-
-- (BOOL)isUnauthenticated {
- return self.UID == nil;
-}
-
-@end
-
-NS_ASSUME_NONNULL_END