Google登录HTML API重定向模式下data-state参数未回传求助
问题排查:Google登录重定向模式下
data-state参数未回传 核心问题定位
你遇到的data-state未在回调中回传的问题,主要有两个关键原因:
1. data-state配置位置错误
在**重定向模式(ux_mode=redirect)**下,data-state参数需要配置在g_id_onload元素中,而非g_id_signin按钮元素里。Google HTML API在重定向模式下会优先读取g_id_onload中的配置项,按钮元素的data-state不会被识别。
2. 属性值使用了中文引号
你的HTML代码中,data-client_id和data-state使用的是中文引号“”,而非标准的英文双引号""。浏览器无法正确解析中文引号包裹的属性值,导致Google API无法读取到data-state的设置。
修正后的HTML代码
<script src="https://accounts.google.com/gsi/client" async></script> <div id="g_id_onload" data-client_id="xxxxx.apps.googleusercontent.com" data-context="signin" data-ux_mode="redirect" data-login_uri="http://localhost:8080/googlecallback" data-auto_prompt="false" data-state="/profile"></div> <div class="g_id_signin" data-locale="en-GB" data-type="standard" data-width="350" data-shape="rectangular" data-theme="filled_blue" data-text="signin_with" data-size="medium"> </div>
额外验证步骤
- 修正后测试回调请求,检查POST数据中是否包含
state字段 - 再次核对Google控制台中的授权重定向URI,确认已正确配置为
http://localhost:8080/googlecallback
内容的提问来源于stack exchange,提问作者Armani_bologne
相关产品推荐
相关产品推荐

