我有一个使用 Google 登录的网站。最近,我收到一封来自 Google 的电子邮件,说我将在 4.2024 之前迁移到 Federated CM (FedCM)。我不明白它是什么以及它意味着什么。该电子邮件链接到此页面以获取指导,但我不知道如何在我的代码中实现它。具体来说,我当前的代码如下所示:
<script type='text/javascript' src='https://apis.google.com/js/platform.js?onload=onLoad' async defer></script>
<meta name='google-signin-client_id' content='$GLOBALS[google_signin_client_id].apps.googleusercontent.com'>
<style>
iframe#ssIFrame_google {display:none}
</style>
<script type='text/javascript'>
function onLoad() {
if (!gapi.auth2) {
gapi.load('auth2', function() {
gapi.auth2.init();
});
}
}
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
var redirectUrl = '?followup=$followup&id='+encodeURIComponent(profile.getId())+'&name='+encodeURIComponent(profile.getName())+'&email='+encodeURIComponent(profile.getEmail())+'&image='+encodeURIComponent(profile.getImageUrl());
window.location = redirectUrl;
}
</script>
迁移指南中的第一步说:
- 添加布尔标志以在初始化时启用 FedCM:
HTML,将 data-use_fedcm_for_prompt 属性设置为 true。
JavaScript,在 IdConfiguration 对象中将 use_fedcm_for_prompt 设置为 true。
在我的代码中,我没有看到需要在哪里将 data-use_fedcm_for_prompt 标志设置为 true(确切地说在哪个对象上)?我没有看到任何 IdConfiguration 项目。
我需要做什么才能成功迁移?
将 platform.js 脚本替换为 FedCM 客户端库
<script src="https://accounts.google.com/gsi/client" async></script>
对于 FedCM 提示,我认为事情就是这样,将跳过 HTML 并使用 JavaScript 在gapi.auth2.init() 函数中加载 FedCM。
<script type='text/javascript'>
function onLoad() {
if (!gapi.auth2) {
gapi.load('auth2', function() {
gapi.auth2.init();
use_fedcm_for_prompt: true // Enable FedCM
});
}
}
我想就是这样,希望有帮助