给定的客户端 ID (GSI) 不允许给定的来源

新手上路,请多包涵

我重构了我的“使用 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 许可协议

阅读 2.1k
2 个回答

我添加了没有端口的 origin 来解决这个问题。

要点:将 http://localhosthttp://localhost: 添加到 Authorized JavaScript origins 框以进行本地测试或开发。

来源: https ://developers.google.com/identity/gsi/web/guides/get-google-api-clientid

原文由 Crow 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题