问题描述
我尝试发布多个范围值,以允许我的应用程序用于某些Google服务...
I try to post several scope values to allow my application for some google service...
我尝试了两个输入字段
<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" />
,其中一个输入字段带有+分隔符
and with one input field with + separator
<input type="hidden" name="scope" value="https://www.googleapis.com/auth/calendar+https://www.googleapis.com/auth/userinfo.email" />
当我仅在一个范围内发送表单时,它起作用.否则,如果使用sereval范围值,google会使用以下错误说明重定向我:
When I send my form with only one scope It work.otherwise with sereval scope value google redirect me with this error description :
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入门中,它可以正常工作有两个范围值.
In the google getting started with oAuth2 it works with two scope values.
这是我的代码:
<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>
推荐答案
将它们组合到单个字段中时,您走在正确的轨道上.请求中只能有一个作用域参数,其值用空格分隔.如果您以这种形式放置它,浏览器将为您编码空间.
You were on the right track when you combined them to a single field. There should be only one scope parameter in the request, with the values separated by spaces. If you're putting it in a form like that, the browser will take care of encoding the space for you.
<input type="hidden" name="scope" value="https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.email" />
这篇关于多个范围值到oauth2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!