在重定向期间,Google oauth2的状态参数的URL编码会被解码

时间:2013-02-13 14:51:12

标签: google-oauth

我正在对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& 状态= 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

注意未编码的“?”字符现在在“state”参数中。这是重定向时Google的问题吗?我读了一篇帖子,建议使用base64编码我可以做的参数,但我想了解为什么它没有使用URL编码。

***修改

以下是来自Google的原始302。应与上面粘贴的网址相同。

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

2 个答案:

答案 0 :(得分:1)

网址编码不需要编码'?'当显示为查询参数值时,或':'或'/'。因此,Google生成的响应已正确编码,不应导致服务器上的任何解析错误。

答案 1 :(得分:0)

对整个状态参数进行Base64编码是一种安全的方法,可以像发送它一样完全恢复它。