oauth2的多个范围值

Chr*_*ove 54 oauth google-api oauth-2.0

我尝试发布sereval范围值,以允许我的应用程序的一些谷歌服务...

我尝试了两个输入字段

<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" />
Run Code Online (Sandbox Code Playgroud)

并带有一个带+分隔符的输入字段

<input type="hidden" name="scope" value="https://www.googleapis.com/auth/calendar+https://www.googleapis.com/auth/userinfo.email" />  
Run Code Online (Sandbox Code Playgroud)

当我发送只有一个范围的表单时它工作.否则与sereval范围值谷歌重定向我与此错误描述:

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 
Run Code Online (Sandbox Code Playgroud)

在google 开始使用oAuth2时,它可以使用两个范围值.

这是我的代码:

  <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>
Run Code Online (Sandbox Code Playgroud)

Ste*_*zyl 101

将它们组合到单个字段时,您处于正确的轨道上.请求中应该只有一个范围参数,值以空格分隔.如果你把它放在这样的形式,浏览器将负责为你编码空间.

<input type="hidden" name="scope" value="https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.email" />
Run Code Online (Sandbox Code Playgroud)

  • 对于好奇的,[RFC 6749,第3.3节](https://tools.ietf.org/html/rfc6749#section-3.3)将`scope`参数定义为`scope参数的值表示为列表以空格分隔的区分大小写的字符串. (5认同)
  • 目前在2017年你应该使用`value ="https://www.googleapis.com/auth/calendar email"` (2认同)