2011-12-09 11 views
41
Biraz google hizmeti için başvurumu izin sereval kapsam değerlerini yayınlamaya çalışan

OAuth2'ye ...Çoklu Kapsam Değerler

iki giriş alanına

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

ile ve + ile bir giriş alanına sahip çalıştı ayırıcı

<input type="hidden" name="scope" value="https://www.googleapis.com/auth/calendar+https://www.googleapis.com/auth/userinfo.email" /> 

Formumu yalnızca bir kapsam ile gönderdiğimde Bu çalışır. aksi sereval kapsam değeri ile google bu hata bilgi ile beni yönlendirmek:

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 

iki kapsam değerlerle çalışır OAuth2 ile google getting started yılında. Tek bir alanda bunları birleştirildiğinde

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

cevap

85

Sen doğru yolda:

İşte benim kodudur. İstekler, boşluklarla ayrılmış değerler ile yalnızca bir kapsam parametresi olmalıdır. Eğer böyle bir formda koyuyorsanız, tarayıcı alanı sizin için kodlamaya özen gösterecektir.

<input type="hidden" name="scope" value="https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.email" /> 
+0

Ben tomorow kadar benim koduna sahip ama –

+2

şu anda 2017 yılında size '' value = "https://www.googleapis.com/auth/calendar email" kullanmalıdır garip görünüyor eğer evan teşekkür etme – user3479125

+3

Merak için, [RFC 6749, Bölüm 3.3] (https://tools.ietf.org/html/rfc6749#section-3.3), "scope" parametresini "scope parametresinin değeri" olarak tanımlar. boşlukla ayrılmış, büyük küçük harf duyarlı dizeler. – davidjb