我试图提交多个作用域值以允许我的应用程序使用一些Google服务...
我尝试使用两个输入字段。
<input type="hidden" name="scope" value="https://www.googleapis.com/auth/calendar" />
<input type="hidden" name="scope" value="https://www.googleapis.com/auth/userinfo.email" />
只有一个带有 + 分隔符的输入字段
<input type="hidden" name="scope" value="https://www.googleapis.com/auth/calendar+https://www.googleapis.com/auth/userinfo.email" />
当我只发送一个作用域的表单时,它可以工作。 否则,当我发送多个作用域值的表单时,谷歌会将我重定向,并显示以下错误描述:
http://localhost:49972/redirect.aspx#error=invalid_request&error_description=OAuth+2+parameters+can+only+have+a+single+value:+scope&error_uri=http://code.google.com/apis/accounts/docs/OAuth2.html
在Google的OAuth2入门中,formingtheurl支持两种范围值。
这是我的代码:
<form id="form1" method="post" action="https://accounts.google.com/o/oauth2/auth?" >
<div>
<input type="hidden" name="response_type" value="code" />
<input type="hidden" name="client_id" value="my client id" />
<input type="hidden" name="redirect_uri" value="http://localhost:49972/redirect.aspx" />
<input type="hidden" name="scope" value="https://www.googleapis.com/auth/calendar" />
<input type="hidden" name="scope" value="https://www.googleapis.com/auth/userinfo.email" />
<input type="hidden" name="state" value="/profile" />
<input type="submit" value="go" />
</div>
</form>
value="https://www.googleapis.com/auth/calendar email"
。 - Ivan Borshchovscope
参数定义为“作用域参数的值表示为一串以空格分隔、区分大小写的字符串列表”。 - davidjb