2011-12-09 5 views
41
좀 구글 서비스에 대한 내 응용 프로그램을 허용하는 sereval 범위의 값을 게시하려고

을 OAuth2를 위해 ...여러 범위의 값

나는 두 개의 입력 필드

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

범위를 하나만 사용하여 양식을 보낼 때 작동합니다. 그렇지 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 

그것을 두 범위의 값으로 작동 OAUTH2 구글 getting started있다. 당신은 하나의 필드 로 결합 될 때

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

답변

85

당신은 바른 길에 있었다 :

여기 내 코드입니다. 요청에는 범위 매개 변수가 하나만 있어야하며 값은 공백으로 구분해야합니다. 이와 같은 형식으로 입력하면 브라우저에서 공간 인코딩을 처리합니다.

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

나는 tomorow까지 내 코드를 가지고 있지만 –

+2

현재 2017 년 당신이''값 = "https://www.googleapis.com/auth/calendar 이메일"을 사용한다 이상한 것 같다 경우 에반 감사하지 않습니다 – user3479125

+3

궁금한 점이 있다면, [RFC 6749, Section 3.3] (https://tools.ietf.org/html/rfc6749#section-3.3)은'scope' 매개 변수를''scope 매개 변수의 값을리스트로 표현합니다 대문자와 소문자가 구별 된 문자열'을 사용합니다. – davidjb

관련 문제