为 Google Oauth2 重定向提供 login_hint 选项

Providing login_hint option for Google Oauth2 redirect

我正在传递 login_hint=1 选项作为 Oauth2 请求查询字符串的一部分,但是当我在接受它后收到来自 Google Oauth2 的回调时,这并没有出现。

我只得到: google/oauth2callback?code=4/vadsdaalijfqwo8fdjqojcxadassddsa#

我期待 1(用户 ID)作为回调的一部分返回。

我如何确保在我的回调中重定向后得到这个提示?

您应该将变量传递给 state。在回调参数中,您可以从 state 参数解析变量。

例如,

https://accounts.google.com/o/oauth2/auth?scope=email profile&state={"user_id": 1}&redirect_uri=http://localhost&response_type=code&client_id=xxxxxxxx.apps.googleusercontent.com&approval_prompt=force

回调 url 将是 http://localhost/code?state={"user_id": 1}&code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7