发布时间: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"
}
}]
}
});
确保您的服务器端逻辑在 ID 断言端点的 params 对象中需要 nonce。
将 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 代码库中提交问题。
- 加入我们的开发者简报邮寄名单,及时了解最新公告。