【问题标题】:URL encoding of the state parameter for Google oauth2 gets decoded during redirectGoogle oauth2 的状态参数的 URL 编码在重定向期间被解码
【发布时间】:2013-01-29 03:47:17
【问题描述】:

我正在为访问 Google 云端硬盘进行初始授权。我想在“state”参数中传递一个完整的 URL,这样我就可以从我在“redirect_uri”中发送的页面名称进行额外的重定向。所以我的请求 URL 看起来像这样......

https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=000000000000.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fmy.server.com%2Fx%2Fws-catch.php&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=offline&state=https%3a%2f%2fmy.server.com%2fRoot%2fDirectory%2fGoogle.php%3fpid%3dc907a55c-87f8-4ba8-8a16-478a9e6cba70%26prov%3dsrv50758c7a0cfcd6。 527662862

请注意,“state”参数是 URL 编码的。谷歌文档说这个参数是往返的,所以我得到了我传入的值。但是,当它到达“redirect_uri”中指定的页面时,状态参数似乎已经部分解码。这是当我拒绝身份验证请求时浏览器会去哪里...

https://my.server.com/x/ws-catch.php?error=access_denied&state=https://my.server.com/Root/Directory/Google.php?pid%3Dc907a55c-87f8-4ba8-8a16-478a9e6cba70%26prov%3Dsrv50758c7a0cfcd6.527662862

注意未编码的“?”字符现在在“状态”参数中。这是谷歌重定向时的问题吗?我读过一篇文章建议对我可以做的参数进行 base64 编码,但我想了解为什么它不能使用 URL 编码。

***编辑

这是来自 Google 的原始 302。应该与上面粘贴的 URL 相同。

HTTP/1.1 302 Moved Temporarily
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Thu, 14 Feb 2013 16:23:37 GMT
Location: https://my.server.com/x/ws-catch.php?error=access_denied&state=https://my.server.com/Root/Directory/Google.php?pid%3Dc907a55c-87f8-4ba8-8a16-478a9e6cba70%26prov%3Dsrv50758c7a0cfcd6.527662862
Content-Type: text/html; charset=UTF-8
Content-Encoding: gzip
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Content-Length: 325
Server: GSE

【问题讨论】:

  • 你确定不是你的浏览器做的吗?我相信 chrome 倾向于解码 URL。您是否尝试过从 Google 获取原始 302?

标签: google-oauth


【解决方案1】:

URL 编码不需要 '?' 编码或 ':' 或 '/' 当作为查询参数值出现时。因此,Google 生成的响应已正确编码,不会导致您的服务器出现任何解析错误。

【讨论】:

    【解决方案2】:

    对整个 state 参数进行 Base64 编码是一种安全的方式,可以完全按照您发送的方式取回它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-23
      • 1970-01-01
      • 2019-10-23
      • 2018-02-25
      • 2021-06-21
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      相关资源
      最近更新 更多