我重构了我的“使用 Google 登录”,将 gapi
替换为 gsi
on http://localhost:8080
。
gapi
怎么能毫无问题地工作,而 gsi
声称 The given origin is not allowed for the given client ID
。
加皮
<script src="https://apis.google.com/js/api:client.js" async defer></script>
window.gapi.load('auth2', () => {
const auth2 = window.gapi.auth2.init({ client_id })
auth2.signIn().then(console.log)
})
gsi
<script src="https://accounts.google.com/gsi/client" async defer></script>
<div id="g_id_onload"
:data-client_id="client_id"
data-login_uri="http://localhost:8080"
data-auto_prompt="false">
</div>
<div class="g_id_signin"
data-type="standard"
data-size="large"
data-theme="outline"
data-text="sign_in_with"
data-shape="rectangular"
data-logo_alignment="left">
</div>
错误: The given origin is not allowed for the given client ID
原文由 Crow 发布,翻译遵循 CC BY-SA 4.0 许可协议
我添加了没有端口的 origin 来解决这个问题。
来源: https ://developers.google.com/identity/gsi/web/guides/get-google-api-clientid