Skip to content

port Firestore Auth module in C++ #733

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

Merged
merged 20 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@
AB380D04201BC6E400D97691 /* ordered_code_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB380D03201BC6E400D97691 /* ordered_code_test.cc */; };
AB38D93020236E21000A432D /* database_info_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB38D92E20235D22000A432D /* database_info_test.cc */; };
AB7BAB342012B519001E0872 /* geo_point_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB7BAB332012B519001E0872 /* geo_point_test.cc */; };
ABC1D7DC2023A04B00BA84F0 /* credentials_provider_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB38D9342023966E000A432D /* credentials_provider_test.cc */; };
ABC1D7DD2023A04F00BA84F0 /* empty_credentials_provider_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB38D93620239689000A432D /* empty_credentials_provider_test.cc */; };
ABC1D7DE2023A05300BA84F0 /* user_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB38D93220239654000A432D /* user_test.cc */; };
ABC1D7E12023A40C00BA84F0 /* token_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABC1D7DF2023A3EF00BA84F0 /* token_test.cc */; };
ABC1D7E42024AFDE00BA84F0 /* firebase_credentials_provider_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABC1D7E22023CDC500BA84F0 /* firebase_credentials_provider_test.mm */; };
ABE6637A201FA81900ED349A /* database_id_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB71064B201FA60300344F18 /* database_id_test.cc */; };
ABF6506C201131F8005F2C74 /* timestamp_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABF6506B201131F8005F2C74 /* timestamp_test.cc */; };
AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; };
Expand Down Expand Up @@ -336,8 +341,13 @@
AB380D01201BC69F00D97691 /* bits_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bits_test.cc; path = ../../core/test/firebase/firestore/util/bits_test.cc; sourceTree = "<group>"; };
AB380D03201BC6E400D97691 /* ordered_code_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ordered_code_test.cc; path = ../../core/test/firebase/firestore/util/ordered_code_test.cc; sourceTree = "<group>"; };
AB38D92E20235D22000A432D /* database_info_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = database_info_test.cc; sourceTree = "<group>"; };
AB38D93220239654000A432D /* user_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = user_test.cc; sourceTree = "<group>"; };
AB38D9342023966E000A432D /* credentials_provider_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = credentials_provider_test.cc; sourceTree = "<group>"; };
AB38D93620239689000A432D /* empty_credentials_provider_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = empty_credentials_provider_test.cc; sourceTree = "<group>"; };
AB71064B201FA60300344F18 /* database_id_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = database_id_test.cc; sourceTree = "<group>"; };
AB7BAB332012B519001E0872 /* geo_point_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = geo_point_test.cc; path = ../../core/test/firebase/firestore/geo_point_test.cc; sourceTree = "<group>"; };
ABC1D7DF2023A3EF00BA84F0 /* token_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = token_test.cc; sourceTree = "<group>"; };
ABC1D7E22023CDC500BA84F0 /* firebase_credentials_provider_test.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = firebase_credentials_provider_test.mm; sourceTree = "<group>"; };
ABF6506B201131F8005F2C74 /* timestamp_test.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = timestamp_test.cc; sourceTree = "<group>"; };
B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B686F2AD2023DDB20028D6BE /* field_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = field_path_test.cc; sourceTree = "<group>"; };
Expand Down Expand Up @@ -430,6 +440,7 @@
54764FAC1FAA0C390085E60A /* GoogleTests */ = {
isa = PBXGroup;
children = (
AB38D9312023962A000A432D /* auth */,
AB380CF7201937B800D97691 /* core */,
54EB764B202277970088B8F3 /* immutable */,
AB356EF5200E9D1A0089B766 /* model */,
Expand Down Expand Up @@ -589,6 +600,19 @@
path = ../../core/test/firebase/firestore/core;
sourceTree = "<group>";
};
AB38D9312023962A000A432D /* auth */ = {
isa = PBXGroup;
children = (
AB38D9342023966E000A432D /* credentials_provider_test.cc */,
AB38D93620239689000A432D /* empty_credentials_provider_test.cc */,
ABC1D7E22023CDC500BA84F0 /* firebase_credentials_provider_test.mm */,
ABC1D7DF2023A3EF00BA84F0 /* token_test.cc */,
AB38D93220239654000A432D /* user_test.cc */,
);
name = auth;
path = ../../core/test/firebase/firestore/auth;
sourceTree = "<group>";
};
DE0761E51F2FE611003233AF /* SwiftBuildTest */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1252,7 +1276,9 @@
5492E058202154AB00B64F25 /* FSTAPIHelpers.mm in Sources */,
AB380CFB2019388600D97691 /* target_id_generator_test.cc in Sources */,
5492E0A82021552D00B64F25 /* FSTLevelDBLocalStoreTests.mm in Sources */,
ABC1D7DE2023A05300BA84F0 /* user_test.cc in Sources */,
5491BC721FB44593008B3588 /* FSTIntegrationTestCase.mm in Sources */,
ABC1D7DD2023A04F00BA84F0 /* empty_credentials_provider_test.cc in Sources */,
DE2EF0861F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.m in Sources */,
B686F2AF2023DDEE0028D6BE /* field_path_test.cc in Sources */,
5492E03120213FFC00B64F25 /* FSTLevelDBSpecTests.mm in Sources */,
Expand All @@ -1272,6 +1298,7 @@
5492E0AC2021552D00B64F25 /* FSTMutationQueueTests.mm in Sources */,
5492E056202154AB00B64F25 /* FIRFieldPathTests.mm in Sources */,
5492E03220213FFC00B64F25 /* FSTMockDatastore.mm in Sources */,
ABC1D7E12023A40C00BA84F0 /* token_test.cc in Sources */,
AB356EF7200EA5EB0089B766 /* field_value_test.cc in Sources */,
AB7BAB342012B519001E0872 /* geo_point_test.cc in Sources */,
5492E0AD2021552D00B64F25 /* FSTMemoryMutationQueueTests.mm in Sources */,
Expand All @@ -1296,8 +1323,10 @@
5492E068202154B900B64F25 /* FSTQueryTests.mm in Sources */,
5492E0AB2021552D00B64F25 /* StringViewTests.mm in Sources */,
5492E0C92021557E00B64F25 /* FSTRemoteEventTests.mm in Sources */,
ABC1D7E42024AFDE00BA84F0 /* firebase_credentials_provider_test.mm in Sources */,
ABF6506C201131F8005F2C74 /* timestamp_test.cc in Sources */,
5492E0AE2021552D00B64F25 /* FSTLevelDBQueryCacheTests.mm in Sources */,
ABC1D7DC2023A04B00BA84F0 /* credentials_provider_test.cc in Sources */,
5492E059202154AB00B64F25 /* FIRQuerySnapshotTests.mm in Sources */,
5492E050202154AA00B64F25 /* FIRCollectionReferenceTests.mm in Sources */,
5492E0A02021552D00B64F25 /* FSTLevelDBMutationQueueTests.mm in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Firestore/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
# limitations under the License.

add_subdirectory(src/firebase/firestore)
add_subdirectory(src/firebase/firestore/auth)
add_subdirectory(src/firebase/firestore/core)
add_subdirectory(src/firebase/firestore/immutable)
add_subdirectory(src/firebase/firestore/model)
add_subdirectory(src/firebase/firestore/remote)
add_subdirectory(src/firebase/firestore/util)

add_subdirectory(test/firebase/firestore)
add_subdirectory(test/firebase/firestore/auth)
add_subdirectory(test/firebase/firestore/core)
add_subdirectory(test/firebase/firestore/immutable)
add_subdirectory(test/firebase/firestore/model)
Expand Down
52 changes: 52 additions & 0 deletions Firestore/core/src/firebase/firestore/auth/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2018 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.

cc_library(
firebase_firestore_auth_base
SOURCES
credentials_provider.cc
credentials_provider.h
token.cc
token.h
user.cc
user.h
DEPENDS
absl_strings
firebase_firestore_util
)

cc_library(
firebase_firestore_auth_apple
SOURCES
firebase_credentials_provider_apple.h
firebase_credentials_provider_apple.mm
DEPENDS
FirebaseCore
firebase_firestore_auth_base
EXCLUDE_FROM_ALL
)

if(APPLE)
list(APPEND AUTH_DEPENDS firebase_firestore_auth_apple)
endif()

cc_library(
firebase_firestore_auth
SOURCES
empty_credentials_provider.cc
empty_credentials_provider.h
DEPENDS
${AUTH_DEPENDS}
firebase_firestore_auth_base
)
31 changes: 31 additions & 0 deletions Firestore/core/src/firebase/firestore/auth/credentials_provider.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2018 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.
*/

#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"

namespace firebase {
namespace firestore {
namespace auth {

CredentialsProvider::CredentialsProvider() : user_change_listener_(nullptr) {
}

CredentialsProvider::~CredentialsProvider() {
}

} // namespace auth
} // namespace firestore
} // namespace firebase
79 changes: 79 additions & 0 deletions Firestore/core/src/firebase/firestore/auth/credentials_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2018 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.
*/

#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_AUTH_CREDENTIALS_PROVIDER_H_
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_AUTH_CREDENTIALS_PROVIDER_H_

#include <functional>
#include <string>

#include "Firestore/core/src/firebase/firestore/auth/token.h"
#include "Firestore/core/src/firebase/firestore/auth/user.h"
#include "absl/strings/string_view.h"

namespace firebase {
namespace firestore {
namespace auth {

// `TokenErrorListener` is a listener that gets a token or an error.
// token: An auth token as a string, or nullptr if error occurred.
// error: The error if one occurred, or else nullptr.
typedef std::function<void(const Token& token, const absl::string_view error)>
TokenListener;

// Listener notified with a User change.
typedef std::function<void(const User& user)> UserChangeListener;

/**
* Provides methods for getting the uid and token for the current user and
* listen for changes.
*/
class CredentialsProvider {
public:
CredentialsProvider();

virtual ~CredentialsProvider();

/**
* Requests token for the current user, optionally forcing a refreshed token
* to be fetched.
*/
virtual void GetToken(bool force_refresh, TokenListener completion) = 0;

/**
* Sets the listener to be notified of user changes (sign-in / sign-out). It
* is immediately called once with the initial user.
*
* Call with nullptr to remove previous listener.
*/
virtual void SetUserChangeListener(UserChangeListener listener) = 0;

protected:
/**
* A listener to be notified of user changes (sign-in / sign-out). It is
* immediately called once with the initial user.
*
* Note that this block will be called back on an arbitrary thread that is not
* the normal Firestore worker thread.
*/
UserChangeListener user_change_listener_;
};

} // namespace auth
} // namespace firestore
} // namespace firebase

#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_AUTH_CREDENTIALS_PROVIDER_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2018 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.
*/

#define UNUSED(x) (void)(x)

#include "Firestore/core/src/firebase/firestore/auth/empty_credentials_provider.h"

namespace firebase {
namespace firestore {
namespace auth {

void EmptyCredentialsProvider::GetToken(bool force_refresh,
TokenListener completion) {
UNUSED(force_refresh);
if (completion) {
completion({"", User::Unauthenticated()}, "");
}
}

void EmptyCredentialsProvider::SetUserChangeListener(
UserChangeListener listener) {
if (listener) {
listener(User::Unauthenticated());
}
}

} // namespace auth
} // namespace firestore
} // namespace firebase
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2018 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.
*/

#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_AUTH_EMPTY_CREDENTIALS_PROVIDER_H_
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_AUTH_EMPTY_CREDENTIALS_PROVIDER_H_

#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"

namespace firebase {
namespace firestore {
namespace auth {

/** `EmptyCredentialsProvider` always yields an empty token. */
class EmptyCredentialsProvider : public CredentialsProvider {
public:
void GetToken(bool force_refresh, TokenListener completion) override;
void SetUserChangeListener(UserChangeListener listener) override;
};

} // namespace auth
} // namespace firestore
} // namespace firebase

#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_AUTH_EMPTY_CREDENTIALS_PROVIDER_H_
Loading