23
23
#include " app/src/heartbeat/heartbeat_controller_desktop.h"
24
24
#include " app/src/include/firebase/app.h"
25
25
#include " app/src/include/firebase/internal/mutex.h"
26
+ #include " auth/src/desktop/auth_desktop.h"
27
+ #include " auth/src/include/firebase/auth.h"
26
28
#include " firebase/log.h"
27
29
28
30
namespace firebase {
@@ -33,39 +35,9 @@ const char* kHeaderFirebaseLocale = "X-Firebase-Locale";
33
35
34
36
AuthRequest::AuthRequest (::firebase::App& app, const char * schema,
35
37
bool deliver_heartbeat)
36
- : RequestJson(schema) {
37
- // The user agent strings are cached in static variables here to avoid
38
- // dependencies upon other parts of this library. This complication is due to
39
- // the way the tests are currently configured where each library has minimal
40
- // dependencies.
38
+ : RequestJson(schema), app(app) {
39
+ CheckEnvEmulator ();
41
40
42
- CheckEmulator ();
43
- static std::string auth_user_agent; // NOLINT
44
- static std::string extended_auth_user_agent; // NOLINT
45
- static Mutex* user_agent_mutex = new Mutex ();
46
- MutexLock lock (*user_agent_mutex);
47
- if (auth_user_agent.empty ()) {
48
- std::string sdk;
49
- std::string version;
50
- app_common::GetOuterMostSdkAndVersion (&sdk, &version);
51
- // Set the user agent similar to the iOS SDK. Format:
52
- // FirebaseAuth.<platform>/<sdk_version>
53
- assert (!(sdk.empty () || version.empty ()));
54
- std::string sdk_type (sdk.substr (sizeof (FIREBASE_USER_AGENT_PREFIX) - 1 ));
55
- auth_user_agent = std::string (" FirebaseAuth." ) + sdk_type + " /" + version;
56
- // Generage the extended header to set the format specified by b/28531026
57
- // and b/64693042 to include the platform and framework.
58
- // <environment>/<sdk_implementation>/<sdk_version>/<framework>
59
- // where <framework> is '(FirebaseCore|FirebaseUI)'.
60
- extended_auth_user_agent = std::string (app_common::kOperatingSystem ) + " /" +
61
- sdk + " /" + version + " /" + " FirebaseCore-" +
62
- sdk_type;
63
- }
64
- // TODO(b/244643516): Remove the User-Agent and X-Client-Version headers.
65
- if (!auth_user_agent.empty ()) {
66
- add_header (" User-Agent" , auth_user_agent.c_str ());
67
- add_header (" X-Client-Version" , extended_auth_user_agent.c_str ());
68
- }
69
41
if (deliver_heartbeat) {
70
42
std::shared_ptr<heartbeat::HeartbeatController> heartbeat_controller =
71
43
app.GetHeartbeatController ();
@@ -81,6 +53,17 @@ AuthRequest::AuthRequest(::firebase::App& app, const char* schema,
81
53
}
82
54
83
55
std::string AuthRequest::GetUrl () {
56
+ std::string emulator_url;
57
+ Auth* auth_ptr = Auth::GetAuth (&app);
58
+ std::string assigned_emulator_url =
59
+ static_cast <AuthImpl*>(auth_ptr->auth_data_ ->auth_impl )
60
+ ->assigned_emulator_url ;
61
+ if (assigned_emulator_url.empty ()) {
62
+ emulator_url = env_emulator_url;
63
+ } else {
64
+ emulator_url = assigned_emulator_url;
65
+ }
66
+
84
67
if (emulator_url.empty ()) {
85
68
std::string url (kHttps );
86
69
url += kServerURL ;
@@ -94,25 +77,26 @@ std::string AuthRequest::GetUrl() {
94
77
}
95
78
}
96
79
97
- void AuthRequest::CheckEmulator () {
98
- if (!emulator_url.empty ()) {
99
- LogInfo (" Emulator Url already set: %s" , emulator_url.c_str ());
80
+ void AuthRequest::CheckEnvEmulator () {
81
+ if (!env_emulator_url.empty ()) {
82
+ LogInfo (" Environment Emulator Url already set: %s" ,
83
+ env_emulator_url.c_str ());
100
84
return ;
101
85
}
86
+
102
87
// Use emulator as long as this env variable is set, regardless its value.
103
88
if (std::getenv (" USE_AUTH_EMULATOR" ) == nullptr ) {
104
- LogInfo (" Using Auth Prod for testing ." );
89
+ LogInfo (" USE_AUTH_EMULATOR not set ." );
105
90
return ;
106
91
}
107
- LogInfo (" Using Auth Emulator." );
108
- emulator_url.append (kEmulatorLocalHost );
109
- emulator_url.append (" :" );
92
+ env_emulator_url.append (kEmulatorLocalHost );
93
+ env_emulator_url.append (" :" );
110
94
// Use AUTH_EMULATOR_PORT if it is set to non empty string,
111
95
// otherwise use the default port.
112
96
if (std::getenv (" AUTH_EMULATOR_PORT" ) == nullptr ) {
113
- emulator_url .append (kEmulatorPort );
97
+ env_emulator_url .append (kEmulatorPort );
114
98
} else {
115
- emulator_url .append (std::getenv (" AUTH_EMULATOR_PORT" ));
99
+ env_emulator_url .append (std::getenv (" AUTH_EMULATOR_PORT" ));
116
100
}
117
101
}
118
102
0 commit comments