protected void page_load(object sender, EventArgs e) { if (!IsPostBack) { try { IAuthorizationState authorization = googleClient.ProcessUserAuthorization(); if (authorization == null) { googleClient.RequestUserAuthorization(scope: new[] { "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/plus.me" }); googleClient.RequestUserAuthorization(scope: new[] { GoogleClient.Scopes.UserInfo.Profile, GoogleClient.Scopes.UserInfo.Email }); } else { UserCollection list = UserCollection.GetUserCollection(); IOAuth2Graph oauth2Graph = googleClient.GetGraph(authorization); string _email = HttpUtility.HtmlEncode(oauth2Graph.Email); User user = list.Single(a => a.Email == _email); FormsAuthentication.SetAuthCookie(user.Name, true); Response.Redirect("~/Systems/Default.aspx"); } } catch (Exception ex) { } } }
protected void Page_Load(object sender, EventArgs e) { IAuthorizationState authorization = googleClient.ProcessUserAuthorization(); if (authorization == null) { // Kick off authorization request googleClient.RequestUserAuthorization(); // alternatively you can ask for more information // googleClient.RequestUserAuthorization(scope: new[] { GoogleClient.Scopes.UserInfo.Profile, GoogleClient.Scopes.UserInfo.Email }); } else { IOAuth2Graph oauth2Graph = googleClient.GetGraph(authorization); this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name); } }