diff options
author | zxu <zxu@google.com> | 2018-02-27 14:04:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-27 14:04:39 -0500 |
commit | 3e7c062f3baca83fae1937bf60865be0cd18f96d (patch) | |
tree | b9816a635f0deda9601496b0d41f6b064f99d838 /Firestore/Source/Remote/FSTStream.mm | |
parent | 13aeb61de4fac4c0239bcf44a98a7d3aa9203963 (diff) |
replacing Auth by C++ auth implementation (#802)
* lazy replacing FST(Firebase)CredentialsProvider by (Firebase)CredentialsProvider
* lazy replacing FSTUser by User
* adding error-code parameter to TokenListener
* actually use const user& instead of pointer; also add an error util
* add HashUser and pass into the unordered_map
* use User in test
* use c++ CredentialsProvider and subclass in test
* fix unit test
* use explicit capture in lambda instead of capture all by reference
* cache currentUser explicitly when reset sync engineer test driver
* objc object should be captured by value in lambda
* replacing Auth/FSTUser by C++ auth implementation
* address changes
* replacing FSTGetTokenResult by C++ Token implementation
* address changes
* fix unintentional change in merging
* patch the change in objc Auth up-stream
* somehow, the lambda-version of set-user-change-listener does not work... fallback to block
* address changes
* fix another const& v.s. dispatch bug
* fix more const& v.s. dispatch bug zxu123 committed
* fix a bad sync line
* address changes
* address change
* address change
* fix upstream change from merge
* fix upstream changes
* Suggested fixes for cpp/port_auth (#846)
* Get rid of MockDatastore factory
This avoids the need to statically allocate (and leak) a credentials
provider
* Use absl::make_unique
std::make_unique technically does not exist until C++14.
* #include <utility> for std::move
* Use std::future for the initial user
* fix style
Diffstat (limited to 'Firestore/Source/Remote/FSTStream.mm')
-rw-r--r-- | Firestore/Source/Remote/FSTStream.mm | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/Firestore/Source/Remote/FSTStream.mm b/Firestore/Source/Remote/FSTStream.mm index a9aa245..6bec3ad 100644 --- a/Firestore/Source/Remote/FSTStream.mm +++ b/Firestore/Source/Remote/FSTStream.mm @@ -21,7 +21,6 @@ #import "FIRFirestoreErrors.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" -#import "Firestore/Source/Auth/FSTCredentialsProvider.h" #import "Firestore/Source/Local/FSTQueryData.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Remote/FSTBufferedWriter.h" @@ -38,9 +37,11 @@ #include "Firestore/core/src/firebase/firestore/auth/token.h" #include "Firestore/core/src/firebase/firestore/core/database_info.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" +#include "Firestore/core/src/firebase/firestore/util/error_apple.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace util = firebase::firestore::util; +using firebase::firestore::auth::CredentialsProvider; using firebase::firestore::auth::Token; using firebase::firestore::core::DatabaseInfo; using firebase::firestore::model::DatabaseId; @@ -103,12 +104,12 @@ typedef NS_ENUM(NSInteger, FSTStreamState) { */ - (instancetype)initWithDatabase:(const DatabaseInfo *)database workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue - credentials:(id<FSTCredentialsProvider>)credentials + credentials:(CredentialsProvider *)credentials serializer:(FSTSerializerBeta *)serializer NS_DESIGNATED_INITIALIZER; - (instancetype)initWithDatabase:(const DatabaseInfo *)database workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue - credentials:(id<FSTCredentialsProvider>)credentials + credentials:(CredentialsProvider *)credentials responseMessageClass:(Class)responseMessageClass NS_UNAVAILABLE; @end @@ -126,7 +127,7 @@ typedef NS_ENUM(NSInteger, FSTStreamState) { // Does not own this DatabaseInfo. @property(nonatomic, assign, readonly) const DatabaseInfo *databaseInfo; @property(nonatomic, strong, readonly) FSTDispatchQueue *workerDispatchQueue; -@property(nonatomic, strong, readonly) id<FSTCredentialsProvider> credentials; +@property(nonatomic, assign, readonly) CredentialsProvider *credentials; @property(nonatomic, unsafe_unretained, readonly) Class responseMessageClass; @property(nonatomic, strong, readonly) FSTExponentialBackoff *backoff; @@ -213,7 +214,7 @@ static const NSTimeInterval kIdleTimeout = 60.0; workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue connectionTimerID:(FSTTimerID)connectionTimerID idleTimerID:(FSTTimerID)idleTimerID - credentials:(id<FSTCredentialsProvider>)credentials + credentials:(CredentialsProvider *)credentials responseMessageClass:(Class)responseMessageClass { if (self = [super init]) { _databaseInfo = database; @@ -263,13 +264,14 @@ static const NSTimeInterval kIdleTimeout = 60.0; FSTAssert(_delegate == nil, @"Delegate must be nil"); _delegate = delegate; - [self.credentials getTokenForcingRefresh:NO - completion:^(Token result, NSError *_Nullable error) { - error = [FSTDatastore firestoreErrorForError:error]; - [self.workerDispatchQueue dispatchAsyncAllowingSameQueue:^{ - [self resumeStartWithToken:result error:error]; - }]; - }]; + _credentials->GetToken( + /*force_refresh=*/false, + [self](Token result, const int64_t error_code, const absl::string_view error_msg) { + NSError *error = util::WrapNSError(error_code, error_msg); + [self.workerDispatchQueue dispatchAsyncAllowingSameQueue:^{ + [self resumeStartWithToken:result error:error]; + }]; + }); } /** Add an access token to our RPC, after obtaining one from the credentials provider. */ @@ -614,7 +616,7 @@ static const NSTimeInterval kIdleTimeout = 60.0; - (instancetype)initWithDatabase:(const DatabaseInfo *)database workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue - credentials:(id<FSTCredentialsProvider>)credentials + credentials:(CredentialsProvider *)credentials serializer:(FSTSerializerBeta *)serializer { self = [super initWithDatabase:database workerDispatchQueue:workerDispatchQueue @@ -699,7 +701,7 @@ static const NSTimeInterval kIdleTimeout = 60.0; - (instancetype)initWithDatabase:(const DatabaseInfo *)database workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue - credentials:(id<FSTCredentialsProvider>)credentials + credentials:(CredentialsProvider *)credentials serializer:(FSTSerializerBeta *)serializer { self = [super initWithDatabase:database workerDispatchQueue:workerDispatchQueue |