多个范围值到oauth2 [英] Multiple Scope Values to oauth2

查看:117
本文介绍了多个范围值到oauth2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试发布sereval作用域值以允许我的应用程序使用一些Google服务...

我尝试过使用两个输入字段

 < input type =hiddenname =scopevalue =https://www.googleapis.com/auth/calendar/> 
< input type =hiddenname =scopevalue =https://www.googleapis.com/auth/userinfo.email/>

以及带有分隔符的一个输入字段

 < input type =hiddenname =scopevalue =https://www.googleapis.com/auth/calendar+https://www.googleapis.com /auth/userinfo.email/> 

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

  http:// localhost:49972 / redirect的.aspx#误差= INVALID_REQUEST&安培; ERROR_DESCRIPTION = OAuth的+ 2个+ +参数可以只+ + +有一个+单个+值:+范围&安培; error_uri = HTTP://code.google.com/apis/accounts/docs/OAuth2。 html 

在google 入门与oAuth2一起使用,它具有两个范围值。



以下是我的代码:

 < form id = form1method =postaction =https://accounts.google.com/o/oauth2/auth? > 
< div>
< input type =hiddenname =response_typevalue =code/>
< input type =hiddenname =client_idvalue =我的客户端ID/>
< input type =hiddenname =redirect_urivalue =http:// localhost:49972 / redirect.aspx/>
< input type =hiddenname =scopevalue =https://www.googleapis.com/auth/calendar/>
< input type =hiddenname =scopevalue =https://www.googleapis.com/auth/userinfo.email/>

< input type =hiddenname =statevalue =/ profile/>
< input type =submitvalue =go/>
< / div>
< / form>


解决方案

当您将它们组合到单个字段
。请求中只能有一个scope参数,值之间用空格分隔。如果你把它放在这样的表单中,浏览器会为你编码空间。

 < input type =hiddenname =scopevalue =https://www.googleapis.com/ auth / calendar https://www.googleapis.com/auth/userinfo.email/> 


I try to post sereval scope values to allow my application for some google service...

I tried with two input field

<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" />  

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 

In the google getting started with oAuth2 it works with two scope values.

Here is my code :

  <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆