Exemplo n.º 1
0
        private async Task <string> LoginSocialUser(SocialUserDetails userDetails)
        {
            var user = await _userManager.FindByEmailAsync(userDetails.Email);

            if (user != null)
            {
                return(await GetAuthenticationResultForUserAsync(user));
            }
            else
            {
                var newUser = new AppUser();
                newUser.Email    = userDetails.Email;
                newUser.Id       = userDetails.Id;
                newUser.UserName = userDetails.Email;
                var identityResult = await _userManager.CreateAsync(newUser);

                Debug.WriteLine("Google user was registered in the system with email: " + newUser.Email);
                if (identityResult.Succeeded)
                {
                    return(await GetAuthenticationResultForUserAsync(newUser));
                }
                else
                {
                    throw new Exception("Couldn't create user");
                }
            }
        }
Exemplo n.º 2
0
        public async Task <SocialUserDetails> getGoogleUserInfo(string token)
        {
            var payload = await validateToken(token);

            var googleUserDetails = new SocialUserDetails();

            googleUserDetails.Email     = payload.Email;
            googleUserDetails.FirstName = payload.GivenName;
            googleUserDetails.LastName  = payload.FamilyName;
            googleUserDetails.Id        = Guid.NewGuid().ToString();
            return(googleUserDetails);
        }