Google oauth2的状态参数的URL编码在重定向过程中被解码



我正在为Google Drive访问进行初始授权。我想在"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%2My.server.com%2Fx%2Fws catch.php&scope=https%3A%2F%2Fww.googleapis.com%2Fat%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&州=https://my.server.com/Root/Directory/Google.php?pid%3Dc907a55c-87f8-4ba8-8a16-478a9e6cba70%26prov%3DSrv50758c7a0fcd6.527662862

请注意,现在"state"参数中有未编码的"?"字符。这是谷歌重定向时的问题吗?我读过一篇帖子,建议对参数进行base64编码,我可以这样做,但我想了解为什么它不能与URL编码一起工作。

***编辑

这是来自谷歌的原始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

URL编码不需要编码"?"或":"或"/"。因此,谷歌生成的响应是正确编码的,不会在服务器上导致任何解析错误。

Base64对整个状态参数进行编码是安全的方法,可以使其完全按照您发送的方式返回。

最新更新