Login with Google on Web Application

Default.aspx
  1.    <div>         
  2.        <a href="#" class="button" id="A1" onclick="OpenGoogleLoginPopup();" name="butrequest">  
  3.            <span>Login with google</span></a>  
  4.        <br />  
  5.         Google ID : <%=Google_ID%> <br />
  6.         Email/user name : <%=Email_address%>   <br />
  7.         first name  : <%=firstName%>   <br />
  8.         Last name  : <%=LastName%>   <br />
  9.                
  10.    </div>  
  11.    <script type="text/javascript" language="javascript">  
  12.        function OpenGoogleLoginPopup() {  
  13.            var url = "https://accounts.google.com/o/oauth2/auth?";  
  14.            url += "scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email&";  
  15.            url += "state=%2Fprofile&"  
  16.            url += "redirect_uri=<%=Return_url %>&"  
  17.            url += "response_type=token&"  
  18.            url += "client_id=<%=Client_ID %>";  
  19.            window.location = url;  
  20.        }  
  21.    </script>  
 Default.aspx.cs
  1. public string Email_address = "";  
  2.     public string Google_ID = "";  
  3.     public string firstName = "";  
  4.     public string LastName = "";  
  5.     public string Client_ID = "";  
  6.     public string Return_url = "";  
  7.     protected void Page_Load(object sender, EventArgs e)  
  8.     {  
  9.         if (!this.IsPostBack)  
  10.         {  
  11.             Client_ID = "Your Client ID";  
  12.             Return_url = "Your Redirected URL";  
  13.         }  
  14.         if (Request.QueryString["access_token"] != null)  
  15.         {  
  16.             String URI = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + Request.QueryString["access_token"].ToString();  
  17.   
  18.             WebClient webClient = new WebClient();  
  19.             Stream stream = webClient.OpenRead(URI);  
  20.             string b;  
  21.   
  22.             using (StreamReader br = new StreamReader(stream))  
  23.             {  
  24.                 b = br.ReadToEnd();  
  25.             }  
  26.   
  27.             b = b.Replace("id""").Replace("email""");  
  28.             b = b.Replace("given_name""");  
  29.             b = b.Replace("family_name""").Replace("link""").Replace("picture""");  
  30.             b = b.Replace("gender""").Replace("locale""").Replace(":""");  
  31.             b = b.Replace("\"""").Replace("name""").Replace("{""").Replace("}""");           
  32.   
  33.             Array ar = b.Split(",".ToCharArray());  
  34.             for (int p = 0; p < ar.Length; p++)  
  35.             {  
  36.                 ar.SetValue(ar.GetValue(p).ToString().Trim(), p);  
  37.   
  38.             }  
  39.             Email_address = ar.GetValue(1).ToString();  
  40.             Google_ID = ar.GetValue(0).ToString();  
  41.             firstName = ar.GetValue(4).ToString();  
  42.             LastName = ar.GetValue(5).ToString();  
  43.         }  
  44.     }