-
Notifications
You must be signed in to change notification settings - Fork 124
add UseEmulator api to auth #1437
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 29 commits
352ba83
6ccf941
b1a8d27
64fd592
4d012dc
ce63a9e
1e1a9ce
14ebb5d
62d5c3f
c2e952a
90f2f2d
9e5c7a8
79ee455
26547d6
472fbb3
c459351
5dfcd36
49ca0fc
f3894bf
e6c7bdb
e08a598
fee091a
ac867c1
2d7a50d
9b1492a
bb40854
13196a7
e4887cb
b07e0ce
7f510ae
cd3c0ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
#include "app/src/heartbeat/heartbeat_controller_desktop.h" | ||
#include "app/src/include/firebase/app.h" | ||
#include "app/src/include/firebase/internal/mutex.h" | ||
#include "auth/src/desktop/auth_desktop.h" | ||
#include "auth/src/include/firebase/auth.h" | ||
#include "firebase/log.h" | ||
|
||
namespace firebase { | ||
|
@@ -33,54 +35,22 @@ const char* kHeaderFirebaseLocale = "X-Firebase-Locale"; | |
|
||
AuthRequest::AuthRequest(::firebase::App& app, const char* schema, | ||
bool deliver_heartbeat) | ||
: RequestJson(schema) { | ||
// The user agent strings are cached in static variables here to avoid | ||
// dependencies upon other parts of this library. This complication is due to | ||
// the way the tests are currently configured where each library has minimal | ||
// dependencies. | ||
|
||
CheckEmulator(); | ||
static std::string auth_user_agent; // NOLINT | ||
static std::string extended_auth_user_agent; // NOLINT | ||
static Mutex* user_agent_mutex = new Mutex(); | ||
MutexLock lock(*user_agent_mutex); | ||
if (auth_user_agent.empty()) { | ||
std::string sdk; | ||
std::string version; | ||
app_common::GetOuterMostSdkAndVersion(&sdk, &version); | ||
// Set the user agent similar to the iOS SDK. Format: | ||
// FirebaseAuth.<platform>/<sdk_version> | ||
assert(!(sdk.empty() || version.empty())); | ||
std::string sdk_type(sdk.substr(sizeof(FIREBASE_USER_AGENT_PREFIX) - 1)); | ||
auth_user_agent = std::string("FirebaseAuth.") + sdk_type + "/" + version; | ||
// Generage the extended header to set the format specified by b/28531026 | ||
// and b/64693042 to include the platform and framework. | ||
// <environment>/<sdk_implementation>/<sdk_version>/<framework> | ||
// where <framework> is '(FirebaseCore|FirebaseUI)'. | ||
extended_auth_user_agent = std::string(app_common::kOperatingSystem) + "/" + | ||
sdk + "/" + version + "/" + "FirebaseCore-" + | ||
sdk_type; | ||
} | ||
// TODO(b/244643516): Remove the User-Agent and X-Client-Version headers. | ||
if (!auth_user_agent.empty()) { | ||
add_header("User-Agent", auth_user_agent.c_str()); | ||
add_header("X-Client-Version", extended_auth_user_agent.c_str()); | ||
} | ||
if (deliver_heartbeat) { | ||
std::shared_ptr<heartbeat::HeartbeatController> heartbeat_controller = | ||
app.GetHeartbeatController(); | ||
if (heartbeat_controller) { | ||
std::string payload = heartbeat_controller->GetAndResetStoredHeartbeats(); | ||
std::string gmp_app_id = app.options().app_id(); | ||
if (!payload.empty()) { | ||
add_header(app_common::kApiClientHeader, payload.c_str()); | ||
add_header(app_common::kXFirebaseGmpIdHeader, gmp_app_id.c_str()); | ||
} | ||
} | ||
} | ||
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 part should keep. This is for the new desktop heartbeat Matt implemented. 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 |
||
: RequestJson(schema), app(app) { | ||
CheckEnvEmulator(); | ||
} | ||
|
||
std::string AuthRequest::GetUrl() { | ||
std::string emulator_url; | ||
Auth* auth_ptr = Auth::GetAuth(&app); | ||
std::string assigned_emulator_url = | ||
static_cast<AuthImpl*>(auth_ptr->auth_data_->auth_impl) | ||
->assigned_emulator_url; | ||
if (assigned_emulator_url.empty()) { | ||
emulator_url = env_emulator_url; | ||
} else { | ||
emulator_url = assigned_emulator_url; | ||
} | ||
|
||
if (emulator_url.empty()) { | ||
std::string url(kHttps); | ||
url += kServerURL; | ||
|
@@ -94,25 +64,26 @@ std::string AuthRequest::GetUrl() { | |
} | ||
} | ||
|
||
void AuthRequest::CheckEmulator() { | ||
if (!emulator_url.empty()) { | ||
LogInfo("Emulator Url already set: %s", emulator_url.c_str()); | ||
void AuthRequest::CheckEnvEmulator() { | ||
if (!env_emulator_url.empty()) { | ||
LogInfo("Environment Emulator Url already set: %s", | ||
env_emulator_url.c_str()); | ||
return; | ||
} | ||
|
||
// Use emulator as long as this env variable is set, regardless its value. | ||
if (std::getenv("USE_AUTH_EMULATOR") == nullptr) { | ||
LogInfo("Using Auth Prod for testing."); | ||
LogInfo("USE_AUTH_EMULATOR not set."); | ||
return; | ||
} | ||
LogInfo("Using Auth Emulator."); | ||
emulator_url.append(kEmulatorLocalHost); | ||
emulator_url.append(":"); | ||
env_emulator_url.append(kEmulatorLocalHost); | ||
env_emulator_url.append(":"); | ||
// Use AUTH_EMULATOR_PORT if it is set to non empty string, | ||
// otherwise use the default port. | ||
if (std::getenv("AUTH_EMULATOR_PORT") == nullptr) { | ||
emulator_url.append(kEmulatorPort); | ||
env_emulator_url.append(kEmulatorPort); | ||
} else { | ||
emulator_url.append(std::getenv("AUTH_EMULATOR_PORT")); | ||
env_emulator_url.append(std::getenv("AUTH_EMULATOR_PORT")); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ struct AuthData; | |
class AuthStateListener; | ||
class IdTokenListener; | ||
class PhoneAuthProvider; | ||
class AuthRequest; | ||
struct AuthCompletionHandle; | ||
struct AuthResultCompletionHandle; | ||
class FederatedAuthProvider; | ||
|
@@ -631,6 +632,14 @@ class Auth { | |
void RemoveIdTokenListener(IdTokenListener* listener); | ||
#endif // not SWIG | ||
|
||
#if !defined(DOXYGEN) | ||
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. Should probably hide from SWIG for now (unless the plan is for this to also be visible from Unity) 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 |
||
/// | ||
/// Modify this Auth instance to communicate with the Firebase Authentication | ||
/// emulator. | ||
/// | ||
void useEmulator(std::string host, uint32_t port); | ||
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. "UseEmulator", with a capital U? 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 |
||
#endif //! defined(DOXYGEN), to hide the api from public documentation. | ||
|
||
/// Gets the App this auth object is connected to. | ||
App& app(); | ||
|
||
|
@@ -653,6 +662,7 @@ class Auth { | |
/// @cond FIREBASE_APP_INTERNAL | ||
friend class ::firebase::App; | ||
friend class ::firebase::auth::PhoneAuthProvider; | ||
friend class ::firebase::auth::AuthRequest; | ||
friend class IdTokenRefreshListener; | ||
friend class IdTokenRefreshThread; | ||
friend class UserDataPersist; | ||
|
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.
I'm guessing the user_agent stuff should not be getting removed
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.
I consulted with Shawn and they are actually not needed anymore. Include Shawn to review to confirm
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.
Most of the user-agent stuffs are not used, at least by Platform Logging pipeline, at all, except for the section I commented below. Therefore it is safe to remove.
However, I wonder if this should be in this particular PR.
If you are planning to bundle this change along with emulator support, please make sure you include this information in the commit message, so it does not look like an accident change.
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