2323#include  " app/src/heartbeat/heartbeat_controller_desktop.h" 
2424#include  " app/src/include/firebase/app.h" 
2525#include  " app/src/include/firebase/internal/mutex.h" 
26+ #include  " auth/src/desktop/auth_desktop.h" 
27+ #include  " auth/src/include/firebase/auth.h" 
2628#include  " firebase/log.h" 
2729
2830namespace  firebase  {
@@ -33,39 +35,9 @@ const char* kHeaderFirebaseLocale = "X-Firebase-Locale";
3335
3436AuthRequest::AuthRequest (::firebase::App& app, const  char * schema,
3537 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 ();
4140
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." " /" 
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 + " /" " /" " 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" c_str ());
67-  add_header (" X-Client-Version" c_str ());
68-  }
6941 if  (deliver_heartbeat) {
7042 std::shared_ptr<heartbeat::HeartbeatController> heartbeat_controller =
7143 app.GetHeartbeatController ();
@@ -81,6 +53,17 @@ AuthRequest::AuthRequest(::firebase::App& app, const char* schema,
8153}
8254
8355std::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+ 
8467 if  (emulator_url.empty ()) {
8568 std::string url (kHttps );
8669 url += kServerURL ;
@@ -94,25 +77,26 @@ std::string AuthRequest::GetUrl() {
9477 }
9578}
9679
97- void  AuthRequest::CheckEmulator () {
98-  if  (!emulator_url.empty ()) {
99-  LogInfo (" Emulator Url already set: %s" 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 ());
10084 return ;
10185 }
86+ 
10287 //  Use emulator as long as this env variable is set, regardless its value.
10388 if  (std::getenv (" USE_AUTH_EMULATOR" nullptr ) {
104-  LogInfo (" Using Auth Prod for testing ." 
89+  LogInfo (" USE_AUTH_EMULATOR not set ." 
10590 return ;
10691 }
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 (" :" 
11094 //  Use AUTH_EMULATOR_PORT if it is set to non empty string,
11195 //  otherwise use the default port.
11296 if  (std::getenv (" AUTH_EMULATOR_PORT" nullptr ) {
113-  emulator_url .append (kEmulatorPort );
97+  env_emulator_url .append (kEmulatorPort );
11498 } else  {
115-  emulator_url .append (std::getenv (" AUTH_EMULATOR_PORT" 
99+  env_emulator_url .append (std::getenv (" AUTH_EMULATOR_PORT" 
116100 }
117101}
118102
0 commit comments