<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="GoogleLogin.login" %> <% //if the user logs out, this clears the session and reloads the page. if (Request.QueryString["logout"] == "yes") { Session.Clear(); Response.Redirect("/login.aspx"); } %> Google OAuth2 Authentication Demo, by A Better Geek <% string code = Request.QueryString["code"]; if (code != null && Session["loggedin"] != "yes") { //if there is a "code" value in the querystring and no login session present //then log in using Google string client_id = Request.Cookies["client_id"].Value; string client_secret = Request.Cookies["client_secret"].Value; string redirect_uri = Request.Cookies["redirect_uri"].Value; string grant_type = "authorization_code"; //the state token in the return URL needs to be verified first. string gState = Request["state"]; if (gState == Convert.ToString(Session["state"])) { string gurl = "code=" + code + "&client_id=" + client_id + "&client_secret=" + client_secret + "&redirect_uri=" + redirect_uri + "&grant_type=" + grant_type; Response.Write(GoogleLogin(gurl)); } else { Response.Write("
Please start over. If you're seeing this message, the session ID verification failed.
"); } } else if (Session["loggedin"] == "yes") { Response.Write("
Already logged in. You can logout if you'd like.
"); } else { %>

& response_type=code&scope=openid%20email&state=<%=Session["state"]%>& redirect_uri=<%=Request.Cookies["redirect_uri"].Value%>">Login With Google

<% Response.Write("
Not logged in.
"); } %>