Google Authentication API: how to get gmail user address

I'm learning the Google Authentication API (AuthSub) ... My question is: how do I get the user account information (at least the Gmail address) after passing authentication?

Since currently everything that I will return from the authentication process is a token giving me access to what Google has ever indicated in the area, but there’s no easy way to even get the user login ID (Gmail address) as I can tell ...


If so, which Google service allows me to access user information?

+6
google-api google-authentication authsub
source share
4 answers

Using the Google AppEngine GData services, you can ask the user to give you access to their Google Mail, calendar, Picasa, etc. Check here .

+2
source share

The Google Authentication API is a token-based system for authenticating a valid user. It does not provide any other interface that allows you to return information from the account holder to the authorizer.

+4
source share

You can get some data through the OpenID API with the ax extension. If you check other methods, best of all I will find a call https://www-opensocial.googleusercontent.com/api/people/@me/@self and you will get a name, email address and picture. Be sure to have http://www-opensocial.googleusercontent.com/api in authentication scope.

+2
source share
  [ValidateInput(false)] public ActionResult Authenticate(string returnUrl) { try { logger.Info("" + returnUrl + "] LoginController : Authenticate method start "); var response = openid.GetResponse(); if (response == null) { try { string discoveryuri = "https://www.google.com/accounts/o8/id"; //OpenIdRelyingParty openid = new OpenIdRelyingParty(); var fetch = new FetchRequest();// new var b = new UriBuilder(Request.Url) { Query = "" }; var req = openid.CreateRequest(discoveryuri, b.Uri, b.Uri); fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email); fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName); req.AddExtension(fetch); return req.RedirectingResponse.AsActionResult(); } catch (ProtocolException ex) { logger.ErrorFormat(" LoginController : Authenticate method has error, Exception:" + ex.ToString()); ViewData["Message"] = ex.Message; return View("Login"); } } else { logger.Info("" + returnUrl + "] LoginController : Authenticate method :when responce not null "); switch (response.Status) { case AuthenticationStatus.Authenticated: logger.Info("" + response.Status + "] LoginController : Authenticate method : responce status "); var fetchResponse = response.GetExtension<FetchResponse>(); string email = fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email); string userIPAddress = HttpContext.Request.UserHostAddress; SecurityManager manager = new SecurityManager(); int userID = manager.IsValidUser(email); if (userID != 0) { ViewBag.IsFailed = "False"; logger.Info("" + userID + "] LoginController : Authenticate method : user id id not null "); Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay; Session["UserEmail"] = email; FormsAuthentication.SetAuthCookie(email, false); WebSession.UserEmail = email; WebSession.UserID = userID; UserManager userManager = new UserManager(); WebSession.AssignedSites = userManager.GetAssignedSites(userID); if (!string.IsNullOrEmpty(returnUrl)) { logger.Info("" + returnUrl + "] LoginController : Authenticate method : retutn url not null then return Redirect "); return Redirect(returnUrl); } else { logger.Info("" + returnUrl + "] LoginController : Authenticate method : retutn url null then return RedirectToAction "); // return Redirect("/Home"); } } else { ViewBag.IsFailed = "True"; logger.Info("" + returnUrl + "] LoginController : Authenticate method :user id null "); if (!string.IsNullOrEmpty(returnUrl)) { logger.Info("" + returnUrl + "] LoginController : Authenticate method :and return Redirect "); return Redirect(returnUrl); } else { logger.Info("" + returnUrl + "] LoginController : Authenticate method :and return RedirectToAction "); return View("Index"); } } case AuthenticationStatus.Canceled: logger.Info("" + response.Status + "] LoginController : Authenticate method : AuthenticationStatus.Canceled and return view "); ViewData["Message"] = "Canceled at provider"; return View("Login"); case AuthenticationStatus.Failed: logger.Info("" + response.Status + "] LoginController : Authenticate method : AuthenticationStatus.Failed and return view "); logger.Error(response.Exception.Message); ViewData["Message"] = response.Exception.Message; return View("Login"); } } logger.Info("" + returnUrl + "] LoginController : Authenticate method end and return EmptyResult"); return new EmptyResult(); } catch (Exception ex) { logger.Error(" LoginController : Authenticate method ", ex); throw; } } 
0
source share

All Articles