Pregunta

He estado estudiando el Google API para la autenticación (AuthSub)...Mi pregunta es, ¿cómo puedo hacer que el usuario de la información de la cuenta (al menos su dirección de Gmail) después de que la autenticación ha pasado?

Porque, en la actualidad, todo lo que obtiene del proceso de autenticación es un token de haberme concedido el acceso a los que alguna vez el servicio de Google he especificado en el ámbito de aplicación, pero no hay ninguna manera fácil de conseguir incluso el usuario id de inicio de sesión (dirección de Gmail) como de lo que puedo decir...


Si es así, lo que el servicio de Google me permite acceder a la información del usuario?

¿Fue útil?

Solución

Usando el Google AppEngine GData servicios, puede solicitar al usuario para darle acceso a su cuenta de Google Mail, Calendar, Picasa, etc.Check it out aquí.

Otros consejos

Google API para la Autenticación es un token basado en el sistema para autenticar a un usuario válido.No exponga cualquier otra interfaz que permite obtener información de la cuenta titular de vuelta a la poderdante.

Usted puede obtener algunos de los datos a través de la OpenID API, con el hacha de extensión.Si se autentifica con otros métodos, el mejor que he encontrado está llamando https://www-opensocial.googleusercontent.com/api/people/@me/@self y te nombre, correo electrónico y la imagen.Asegúrese de tener http://www-opensocial.googleusercontent.com/api en los ámbitos de la hora de autenticar.

    [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;
        }
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top