Calling Google OAuth 2.0 with all the parameters , it gives invalid request saying response_type is

617 views
Skip to first unread message

Bhuvin Thakker

unread,
Jun 26, 2012, 6:07:54 AM6/26/12
to oauth...@googlegroups.com

Guyz i have implemented a Android push notification service using Asp.net Mvc 3, Google C2DM with OAuth 2.0. 
At the point of time of implementation it was working fine. Now after starting the testing , Suddenly from yesterday i have been getting invalid_request error saying response_type parameter is missing. enter image description here

  • I have checked the code it gives all the required parameters .
  • I have checked the Request using fiddler it also shows the response_type = code is a post parameter.
  • The google account required is also signed in.

I am not able to understand how to tackle this issue 
Code: 

public string GetAuthenticationCode()
       
{
           
string returnUrl = "";
           
string URL = " https://accounts.google.com/o/oauth2/auth";
           
NameValueCollection postFieldNameValue = new NameValueCollection();
            postFieldNameValue
.Add("response_type", "code");
            postFieldNameValue
.Add("client_id", "xxxxxxxxxxx.apps.googleusercontent.com");
            postFieldNameValue
.Add("redirect_uri", "http://localhost:49882/TestServer/test");
            postFieldNameValue
.Add("scope", "https://android.apis.google.com/c2dm/send");
            postFieldNameValue
.Add("state", "profile");
            postFieldNameValue
.Add("access_type", "offline");
            postFieldNameValue
.Add("approval_prompt", "force");    
       
//Had a doubt the request is cached so added this for the same.
            postFieldNameValue
.Add("additional_param", DateTime.Now.Ticks.ToString());
           
string postData = GetPostStringFrom(postFieldNameValue);
           
byte[] byteArray = Encoding.UTF8.GetBytes(postData);

           
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
           
Request.Method = "POST";
           
Request.KeepAlive = false;

           
Request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
           
Request.ContentLength = byteArray.Length;


           
Stream dataStream = Request.GetRequestStream();
           
// Write the data to the request stream.
            dataStream
.Write(byteArray, 0, byteArray.Length);
           
// Close the Stream object.
            dataStream
.Close();

           
try
           
{
               
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
               
WebResponse Response = Request.GetResponse();

               
var sr = new StreamReader(Response.GetResponseStream());

               
// Debug.WriteLine(sr.ReadToEnd());
               
// returnUrl = sr.ReadToEnd();
                returnUrl
= Response.ResponseUri.ToString();
           
}
           
catch(WebException wex)
           
{
               
var sr = new StreamReader(wex.Response.GetResponseStream());
               
Debug.WriteLine(sr.ReadToEnd());
               
throw;
           
}
           
return returnUrl;
       
}

Other thing is I also tried to make a request after removing the response_type parameter but in that case it will throw Web Exception - Bad request.

access_type : auto is also not working.

I tried to get the content of the response stream and returned as content , it shows google sign in page . If we give the authentication details in there manually it will work . So i am stuck to implement the same . Please help.

Breno de Medeiros

unread,
Jun 26, 2012, 10:36:30 AM6/26/12
to oauth...@googlegroups.com
Please supply the request and response headers in your app's communication with Google. Remember to anonymize sensitive fields, such as cookie values and client_secret (if applicable).

--
You received this message because you are subscribed to the Google Groups "oauth2-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/oauth2-dev/-/pU-6sjxk7x4J.
To post to this group, send email to oauth...@googlegroups.com.
To unsubscribe from this group, send email to oauth2-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/oauth2-dev?hl=en.



--
--Breno

Bhuvin Thakker

unread,
Jun 28, 2012, 8:55:40 AM6/28/12
to oauth...@googlegroups.com
@Breno :

The request params are : 
  Param = "response_type",value= "code"
  Param =
"client_id",value = "xxxxxxxxxxx.apps.googleusercontent.com"
  Param =
"redirect_uri",value = "http://localhost:49882/TestServer/test"
  Param =
"scope",value = "https://android.apis.google.com/c2dm/send"
  Param =
"state",value = "profile"
  Param =
"access_type",value = "offline"
  Param =
"approval_prompt",value = "force"
Response Has the Uri as above.
And the Response content is a google login page .
Reply all
Reply to author
Forward
0 new messages