You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Google登录按钮启用Redirect Mode(Flask-Dance环境)

解决Flask-Dance集成Google官方登录按钮的跳转模式问题

要让Google官方登录按钮使用跳转模式而非弹窗,只需在配置中添加指定参数并确保关键项配置正确:

  • 在#g_id_onload容器中添加data-ux_mode="redirect",强制按钮采用页面跳转而非弹窗模式
  • 确认data-client_id填写的是Google Cloud Console中创建的OAuth客户端ID,需匹配本地域名的授权回调配置
  • 确保Flask-Dance的Google路由/login/google已正确配置回调处理逻辑

修改后的完整HTML代码:

<!-- google oauth -->
<div class="d-flex justify-content-center mt-5 mb-4">
    <div id="g_id_onload" 
        data-client_id="你的Google OAuth客户端ID"
        data-login_uri="http://localhost/login/google" 
        data-auto_prompt="false"
        data-ux_mode="redirect"> <!-- 新增此参数启用跳转模式 -->
    </div>
    <div class="g_id_signin" 
        data-type="standard" 
        data-logo_alignment="center"
        data-size="large" 
        data-theme="filled_blue" 
        data-shape="circle"
        data-text="continue_with"
        data-width=360>
    </div>
</div>

<script src="https://accounts.google.com/gsi/client" async defer></script>

额外注意事项:

  • 检查Google Cloud Console中,OAuth客户端已将http://localhost/login/google/authorized添加到已授权的重定向URI列表(Flask-Dance默认回调路径为原登录路由追加/authorized)
  • 本地测试时请使用http://localhost而非127.0.0.1,避免域名不匹配引发的问题

内容的提问来源于stack exchange,提问作者Rug

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 19:10:33