-
Notifications
You must be signed in to change notification settings - Fork 1.8k
replacing FSTGetTokenResult by C++ Token implementation #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
dc4f02c
b502b8e
bfbb0e2
a64ca8c
9fb7911
369f812
6e4fdef
5cb11ca
6775d9b
7d10621
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -301,22 +301,24 @@ - (void)invokeRPCWithFactory:(GRPCProtoCall * (^)(void))rpcFactory | |
| errorHandler:(FSTVoidErrorBlock)errorHandler { | ||
| // TODO(mikelehen): We should force a refresh if the previous RPC failed due to an expired token, | ||
| // but I'm not sure how to detect that right now. http://b/32762461 | ||
| [self.credentials getTokenForcingRefresh:NO | ||
| completion:^(const Token &result, NSError *_Nullable error) { | ||
| error = [FSTDatastore firestoreErrorForError:error]; | ||
| [self.workerDispatchQueue dispatchAsyncAllowingSameQueue:^{ | ||
| if (error) { | ||
| errorHandler(error); | ||
| } else { | ||
| GRPCProtoCall *rpc = rpcFactory(); | ||
| [FSTDatastore | ||
| prepareHeadersForRPC:rpc | ||
| databaseID:&self.databaseInfo->database_id() | ||
| token:result.token()]; | ||
| [rpc start]; | ||
| } | ||
| }]; | ||
| }]; | ||
| [self.credentials | ||
| getTokenForcingRefresh:NO | ||
| completion:^(const Token &result, NSError *_Nullable error) { | ||
| error = [FSTDatastore firestoreErrorForError:error]; | ||
| [self.workerDispatchQueue dispatchAsyncAllowingSameQueue:^{ | ||
| if (error) { | ||
| errorHandler(error); | ||
| } else { | ||
| GRPCProtoCall *rpc = rpcFactory(); | ||
| [FSTDatastore | ||
| prepareHeadersForRPC:rpc | ||
| databaseID:&self.databaseInfo->database_id() | ||
| token:(result.is_valid() ? result.token() | ||
| : absl::string_view())]; | ||
| [rpc start]; | ||
| } | ||
| }]; | ||
| }]; | ||
| } | ||
|
|
||
| - (FSTWatchStream *)createWatchStream { | ||
|
|
@@ -338,9 +340,12 @@ + (void)prepareHeadersForRPC:(GRPCCall *)rpc | |
| databaseID:(const DatabaseId *)databaseID | ||
| token:(const absl::string_view)token { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (see comment in FSTDatastore.h:87)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| rpc.oauth2AccessToken = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change isn't right. If there's no token this is setting this property to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. empty check might be enough since an empty string token will cause the corruption of http header; so valid token will never be empty string. But let me check the nullptr instead just in case some test (not actually taking via a http call) may use empty string. |
||
| [[NSString alloc] initWithBytes:const_cast<void *>(static_cast<const void *>(token.data())) | ||
| length:token.length() | ||
| encoding:NSUTF8StringEncoding]; | ||
| token.data() == nullptr | ||
| ? nil | ||
| : [[NSString alloc] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this could be a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| initWithBytes:const_cast<void *>(static_cast<const void *>(token.data())) | ||
| length:token.length() | ||
| encoding:NSUTF8StringEncoding]; | ||
| rpc.requestHeaders[kXGoogAPIClientHeader] = [FSTDatastore googAPIClientHeaderValue]; | ||
| // This header is used to improve routing and project isolation by the backend. | ||
| rpc.requestHeaders[kGoogleCloudResourcePrefix] = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| #include <string> | ||
|
|
||
| #include "Firestore/core/src/firebase/firestore/auth/user.h" | ||
| #include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" | ||
| #include "absl/strings/string_view.h" | ||
|
|
||
| namespace firebase { | ||
|
|
@@ -45,6 +46,7 @@ class Token { | |
|
|
||
| /** The actual raw token. */ | ||
| const std::string& token() const { | ||
| FIREBASE_ASSERT(is_valid_); | ||
| return token_; | ||
| } | ||
|
|
||
|
|
@@ -56,9 +58,19 @@ class Token { | |
| return user_; | ||
| } | ||
|
|
||
| bool is_valid() const { | ||
| return is_valid_; | ||
| } | ||
|
|
||
| /** Returns an invalid token. */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a porting note since this concept of an invalid token doesn't exist elsewhere. Something to indicate why we need it, etc.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| static const Token& Invalid(); | ||
|
|
||
| private: | ||
| Token(); | ||
|
|
||
| const std::string token_; | ||
| const User user_; | ||
| const bool is_valid_; | ||
| }; | ||
|
|
||
| } // namespace auth | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The objective-c code suggests this may be nullable? If so a const* may be required rather than const&. OTOH, if an invalid token is represented by a concrete Token object (rather than by null) then this may be fine. (Either way, you may want to adjust the docstring to clarify.)
Update: Oh, I see below that it is indeed a concrete object rather than null, so the signature is fine. Suggested change to the docstring:
@PARAM token An auth token or X
but X depends on what you pass in. (see below). Possibilities:
X=" nil if an error occurred"
X=" Token::invalid() if an error occurred"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. FYI: the code here will be removed by my next PR to replace the rest of Auth.