發布日期:2026 年 1 月 12 日
Chrome 143 推出 Federated Credential Management (FedCM) API 更新,可提升隱私權、開發人員體驗和瀏覽器互通性。這些變更的依據是身分識別提供者 (IdP)、信賴方 (RP) 和網路社群的意見回饋。
主要異動如下:
支援來自 ID 聲明端點的結構化 JSON 回應
先前,FedCM ID 聲明端點要求回應中的 token 屬性為字串。這迫使開發人員必須在伺服器上手動將資料序列化為 JSON 字串,並在用戶端剖析該字串。
自 Chrome 143 起,ID 聲明端點支援結構化 JSON 物件,做為 token 屬性的值,例如:
{
"token": {
"access_token": "a1b2c3d4e5f6...",
"user_info": {
"email": "jane.doe@company.example",
"given_name": "Jane",
"family_name": "Doe"
}
}
}
這項變更可免除手動序列化和剖析 JSON 的需求,並允許 IdP 傳回額外資訊。
請使用 FedCM 示範試用這項功能,或參閱在識別資訊提供者端實作 FedCM 指南,瞭解更新後的 ID 聲明端點回應結構。
驗證用戶端中繼資料
為進一步保護使用者隱私,FedCM 將強化 IdP 端點的驗證機制。這項變更可防止 IdP 將 RP 與做為路徑參數傳遞的專屬 ID 相符。
如果 FedCM 設定使用 client_metadata 端點,則必須在 .well-known/web-identity 檔案中加入 accounts_endpoint 和 login_url。自 Chrome 145 版起,瀏覽器會強制執行知名檔案中的 accounts_endpoint 參數。
{
"accounts_endpoint": "/example-accounts",
"login_url": "/example-login"
}
詳情請參閱 FedCM 導入指南。
更新 API 一致性和錯誤處理機制
Chrome 143 推出兩項變更,可提升 FedCM API 的清晰度和一致性,與網路生態系統意見回饋保持一致。
重新放置 nonce 參數
自 145 版起,Chrome 將停止支援頂層 nonce 參數。您必須在 navigator.credentials.get() 呼叫的 params 物件中傳遞 nonce 參數:
const credential = await navigator.credentials.get({
identity: {
providers: [{
// Don't pass nonce as a top-level parameter here
configURL: "/fedcm.json",
clientId: "123",
params: {
// Place nonce within the params object
nonce: "a-random-nonce"
}
}]
}
});
確認伺服器端邏輯預期 nonce 會位於 ID 聲明端點的 params 物件中。
將 IdentityCredentialError.code 重新命名為 IdentityCredentialError.error
為避免與內建的 DOMException.code 屬性發生命名衝突,IdentityCredentialError.code 已重新命名為 IdentityCredentialError.error。這項異動將在 Chrome 145 版中強制實施。
try {
// FedCM API call
} catch (e) {
// Renamed IdentityCredentialError.code to IdentityCredentialError.error:
console.log(e.error);
}
為確保過渡期間 (Chrome 143 和 144) 的回溯相容性,請在錯誤處理邏輯中檢查 code 和 error 屬性。這樣一來,即使使用者更新至較新版本的 Chrome,您的解決方案也能在舊版瀏覽器中運作:
// In older browsers, the property might still be named 'code'
// during the transition period
const errorCode = e.error ?? e.code;
if (errorCode) {
// Handle specific error types
} else {
console.error("An unknown error occurred", e);
}
詳情請參閱 FedCM 說明文件的「傳回錯誤回應」一節。
提供意見
我們會持續開發及改良 FedCM,並重視您的想法。如有任何意見或遇到問題,請按照下列步驟操作:
- 在 GitHub 存放區中提出問題。
- 加入開發人員電子報郵寄清單,隨時掌握最新公告。