aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm
diff options
context:
space:
mode:
authorGravatar rsgowman <rgowman@google.com>2018-03-21 11:04:40 -0400
committerGravatar GitHub <noreply@github.com>2018-03-21 11:04:40 -0400
commit308acc09bfaf6dabf4b6d5f5e39f33854df8ce34 (patch)
tree3706bbbe40d08569795634fd2f30a07fd348b399 /Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm
parentd924771453d000e708bd5d239da3bae4feb489ac (diff)
Change CredentialsProvider::TokenListener to use StatusOr<Token> (#945)
* Change CredentialsProvider::TokenListener to use StatusOr Rather than a token plus error code/msg. * Eliminate the concept of an invalid Token Instead, we'll just use StatusOr<Token>. Note that unauthenticated tokens are handled as a special case; they're created via: Token::Unauthenticated() and are otherwise "valid", though attempting to retrieve the raw token on one of these tokens will cause an assertion failure.
Diffstat (limited to 'Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm')
-rw-r--r--Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm56
1 files changed, 35 insertions, 21 deletions
diff --git a/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm b/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm
index 1babe82..2bd3acc 100644
--- a/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm
+++ b/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm
@@ -23,6 +23,9 @@
#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
+// NB: This is also defined in Firestore/Source/Public/FIRFirestoreErrors.h
+NSString* const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
+
namespace firebase {
namespace firestore {
namespace auth {
@@ -84,27 +87,38 @@ void FirebaseCredentialsProvider::GetToken(bool force_refresh,
int initial_user_counter = contents_->user_counter;
std::weak_ptr<Contents> weak_contents = contents_;
- void (^get_token_callback)(NSString*, NSError*) = ^(
- NSString* _Nullable token, NSError* _Nullable error) {
- std::shared_ptr<Contents> contents = weak_contents.lock();
- if (!contents) {
- return;
- }
-
- std::unique_lock<std::mutex> lock(contents->mutex);
- if (initial_user_counter != contents->user_counter) {
- // Cancel the request since the user changed while the request was
- // outstanding so the response is likely for a previous user (which
- // user, we can't be sure).
- completion(Token::Invalid(), FirestoreErrorCode::Aborted,
- "getToken aborted due to user change.");
- } else {
- completion(
- Token{util::MakeStringView(token), contents->current_user},
- error == nil ? FirestoreErrorCode::Ok : error.code,
- error == nil ? "" : util::MakeStringView(error.localizedDescription));
- }
- };
+ void (^get_token_callback)(NSString*, NSError*) =
+ ^(NSString* _Nullable token, NSError* _Nullable error) {
+ std::shared_ptr<Contents> contents = weak_contents.lock();
+ if (!contents) {
+ return;
+ }
+
+ std::unique_lock<std::mutex> lock(contents->mutex);
+ if (initial_user_counter != contents->user_counter) {
+ // Cancel the request since the user changed while the request was
+ // outstanding so the response is likely for a previous user (which
+ // user, we can't be sure).
+ completion(util::Status(FirestoreErrorCode::Aborted,
+ "getToken aborted due to user change."));
+ } else {
+ if (error == nil) {
+ if (token != nil) {
+ completion(
+ Token{util::MakeStringView(token), contents->current_user});
+ } else {
+ completion(Token::Unauthenticated());
+ }
+ } else {
+ FirestoreErrorCode error_code = FirestoreErrorCode::Unknown;
+ if (error.domain == FIRFirestoreErrorDomain) {
+ error_code = static_cast<FirestoreErrorCode>(error.code);
+ }
+ completion(util::Status(
+ error_code, util::MakeStringView(error.localizedDescription)));
+ }
+ }
+ };
[contents_->app getTokenForcingRefresh:force_refresh
withCallback:get_token_callback];