[Bug] Desktop Auth token refresh ignores UseEmulator() and targets production
维护者通常 3 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- cpp, unity
调研方向
Start in auth/src/desktop/rpcs/secure_token_request.cc, where the token URL is hard-coded as api_host, and compare it with how auth_request.cc's GetUrl() reads AuthImpl::assigned_emulator_url. Confirm the refresh request is the one hitting production before changing anything, since the reproducer has not been run. Done means GetToken(true) succeeds against the emulator on 127.0.0.1:9099.
由索引模型根据 Issue 内容生成。
描述
[REQUIRED] Please fill in the following fields:
- Pre-built SDK from the website or open-source from this repo: Pre-built native SDK bundled with Firebase Unity SDK 13.17.0.
- Firebase C++ SDK version: 13.13.0.
- Problematic Firebase Component: Auth.
- Other Firebase Components in use: None.
- Platform you are using the C++ SDK on: Mac, through the Unity Editor.
- Platform you are targeting: iOS and Android; the failure occurs in the macOS Unity Editor.
[REQUIRED] Please describe the issue here:
Desktop Auth token refresh appears to ignore the endpoint configured through:
auth->UseEmulator("127.0.0.1", 9099);
Anonymous sign-in succeeds against the emulator. However, requesting an ID token for an existing authenticated user fails with “An internal error has occurred.” The user has a UID and is valid.
The failure was observed through the Unity wrapper. The standalone C++ reproducer below has not yet been compiled or run.
The desktop source shows a discrepancy:
Auth::UseEmulator()stores the configured endpoint inAuthImpl::assigned_emulator_url.AuthRequest::GetUrl()uses that endpoint. Anonymous sign-in uses this method.SecureTokenRequest, used for token refresh, bypassesGetUrl()and constructs a production URL directly:
const char api_host[] =
"https://securetoken.googleapis.com/v1/token?key=";
This appears to send emulator-issued refresh tokens to production. The same hard-coded endpoint is present in the installed macOS native library, although the failing HTTP request has not been captured.
Expected behavior: all Auth requests, including token refresh, should use the configured emulator.
References:
- [UseEmulator implementation PR #1437](https://github.com/firebase/firebase-cpp-sdk/pull/1437)
- [Desktop emulator URL selection](https://github.com/firebase/firebase-cpp-sdk/blob/main/auth/src/desktop/rpcs/auth_request.cc)
- [Desktop token refresh request](https://github.com/firebase/firebase-cpp-sdk/blob/main/auth/src/desktop/rpcs/secure_token_request.cc)
Steps to reproduce:
- Start the Auth emulator on
127.0.0.1:9099. - Create a Firebase app.
- Call
UseEmulator()before performing authentication operations. - Sign in anonymously.
- Call
GetToken(false)to retrieve the fresh cached token. - Call
GetToken(true)to exercise the refresh path immediately.
The observed failure occurs when retrieving a token for an existing authenticated user. Explicitly forcing refresh is proposed here to reproduce the suspected failing path without waiting for token expiration.
Have you reproduced this with the Firebase C++ quickstarts? No.
Issue reproduction rate: Not measured.
Relevant Code:
#include <chrono>
#include <iostream>
#include <memory>
#include <thread>
#include "firebase/app.h"
#include "firebase/auth.h"
template <typename T>
bool WaitForResult(const char* operation,
const firebase::Future<T>& future) {
while (future.status() == firebase::kFutureStatusPending) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
if (future.status() != firebase::kFutureStatusComplete) {
std::cerr << operation << ": invalid future\n";
return false;
}
if (future.error() != 0) {
std::cerr << operation << ": error " << future.error()
<< ": " << future.error_message() << '\n';
return false;
}
std::cout << operation << ": succeeded\n";
return true;
}
int main() {
firebase::AppOptions options;
options.set_project_id("demo-project");
options.set_api_key("fake-api-key");
options.set_app_id("1:1234567890:ios:0000000000000000000000");
std::unique_ptr<firebase::App> app(
firebase::App::Create(options, "auth-emulator-refresh-repro"));
std::unique_ptr<firebase::auth::Auth> auth(
firebase::auth::Auth::GetAuth(app.get()));
auth->UseEmulator("127.0.0.1", 9099);
// Reproduction only: clear cached auth state before creating a new user.
// Read current_user() first to wait for persisted state initialization.
auth->current_user();
auth->SignOut();
auto sign_in = auth->SignInAnonymously();
if (!WaitForResult("Anonymous sign-in", sign_in)) {
return 1;
}
auto user = auth->current_user();
std::cout << "User UID: " << user.uid() << '\n';
auto cached_token = user.GetToken(false);
if (!WaitForResult("Cached token", cached_token)) {
return 1;
}
// Exercise SecureTokenRequest immediately.
auto refreshed_token = user.GetToken(true);
return WaitForResult("Token refresh", refreshed_token) ? 0 : 1;
}
- 主要语言
- C++
- 星标
- 326
- 派生
- 137
- 平均合并
- 2 天 5 小时
- 30 天内合并 PR
- 8
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/firebase-cpp-sdk 的其他 Issue
-
new type: question
难度 2/5 1-3 小时 新手友好度 85/100
firebase/firebase-cpp-sdk#1926 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
firebase/firebase-cpp-sdk#1905 · 2 条评论 ·
维护者通常 3 天内回复
-
难度 3/5 半天 新手友好度 55/100
firebase/firebase-cpp-sdk#1936 ·
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
firebase/firebase-cpp-sdk#1935 ·
维护者通常 3 天内回复
-
api: firestore
难度 5/5 一周以上 新手友好度 35/100
firebase/firebase-cpp-sdk#1920 · 3 条评论 ·
维护者通常 3 天内回复
查看 firebase/firebase-cpp-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
FriendsofECCE/ECCE#336 · 1 条评论 ·
-
error not reported low priority semantics
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
bitcoin-core/gui-qml#1030 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复