client_id
<https://accounts.google.com/o/oauth2/v2/auth>?
scope=https://www.googleapis.com/auth/userinfo.email <https://www.googleapis.com/auth/userinfo.profile&>
response_type=token&
state=g/BDEnNMQjWv9JeA4snvhAyW1qbIFNJGX1mdTajCpFfyYKGRm3bcUIIwKkj25UGT&
redirect_uri=http://127.0.0.1&
client_id=000000196838-ph7moootoln67pi8qifdg7m5hxxxxxx.apps.googleusercontent.com
// See your primary Google Account email address
UserinfoEmailScope = "<https://www.googleapis.com/auth/userinfo.email>"
// See your personal info, including any personal info you've made
UserinfoProfileScope = "<https://www.googleapis.com/auth/userinfo.profile>"
为了严谨,前端会比对
state
的值和生成登录地址时返回的值是否一致,来验证会话的一致性。
在Google账号授权登录接口中,state字段是可选的参数,用于防止跨站点请求伪造攻击(Cross-Site Request Forgery,CSRF)。
CSRF攻击是一种攻击方式,攻击者利用用户已登录的状态,在用户毫不知情的情况下,向目标网站发送恶意请求,从而实现攻击目的。为了防止此类攻击,常常会在发起请求时生成一个随机的字符串作为state参数,并将该字符串存储在服务器端。当Google授权服务器回调时,会将该state参数原样返回。开发者可以在回调处理函数中,比对返回的state参数与发起请求时传入的state参数是否一致,从而确定该回调请求是否为有效请求。
因此,state参数的作用在于增强授权请求的安全性,保障用户的信息安全。需要前端在请求授权登录之前向后端存储state
字段。