예제 #1
0
        private async void ExecuteSocialLoginCommand(SocialLoginModel socialLogin)
        {
            try
            {
                IsBusy = true;
                await Task.Delay(100).ConfigureAwait(true);

                if (socialLogin == null)
                {
                    return;
                }
                var logged = await _client.LoginAsync(socialLogin);

                if (!logged)
                {
                    await DisplayAlert("Erro", "Não foi possível fazer login com " + socialLogin.Name, "OK");

                    return;
                }
                await PushAsync <TopNewsViewModel>();
            }
            catch (Exception ex)
            {
                await DisplayAlert("Erro", ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
        public IActionResult SocialLogin([FromBody] SocialLoginModel socialLoginModel)
        {
            //var test = _appSettings.JWT_Secret;

            if (VerifyToken(socialLoginModel.IdToken).Result)
            {
                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Expires = DateTime.UtcNow.AddMinutes(30),
                    //Key min: 16 characters
                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_appSettings.JWT_Secret)), SecurityAlgorithms.HmacSha256Signature),
                    /*Subject = new ClaimsIdentity(new Claim[]
                    {
                        new Claim(ClaimTypes.Role, "regular_user"),
                        new Claim(ClaimTypes.PrimarySid, loginModel.Id.Substring(0, 13))
                    }),*/
                };
                var tokenHandler = new JwtSecurityTokenHandler();
                var securityToken = tokenHandler.CreateToken(tokenDescriptor);
                var token = tokenHandler.WriteToken(securityToken);

                return Ok(new { token, socAppUser });
            }

            return Ok();
        }
예제 #3
0
        public static SocialLoginModel MapSocialLogin(SocialLogin socialLogin)
        {
            var model = new SocialLoginModel();

            model.Assign(socialLogin);
            return(model);
        }
예제 #4
0
        public static SocialLogin MapSocialLogin(SocialLoginModel model)
        {
            var socialLogin = new SocialLogin();

            socialLogin.Assign(model);
            return(socialLogin);
        }
예제 #5
0
 public UserLoginInfo ToLoginInfo(SocialLoginModel socialLogin)
 {
     if (socialLogin == null)
     {
         return(null);
     }
     return(new UserLoginInfo(socialLogin.Provider, socialLogin.Key, socialLogin.Name));
 }
예제 #6
0
        public async Task AddSocialLogin(string userId, SocialLoginModel model)
        {
            var socialLogin = Core.Infrastructures.Helper.Mapper.MapSocialLogin(model);

            _db.Set <SocialLogin>().Add(socialLogin);
            await _db.SaveChangesAsync();

            model.SocialLoginId = socialLogin.SocialLoginId;
        }
예제 #7
0
        public async Task <TokenResponse> SocialLogin(SocialLoginModel model,
                                                      string deviceToken, Language language, OsType osType, string deviceId, string currencyCode)
        {
            switch (model.Provider)
            {
            case SocialLoginProvider.Facebook:
                return(await ExternalLogin(await FaceBookRequest(model.Token), deviceToken, osType, deviceId, currencyCode));

            case SocialLoginProvider.Google:
                return(await ExternalLogin(await GoogleRequest(model.Token), deviceToken, osType, deviceId, currencyCode));

            default:
                throw new SmartException();
            }
        }
예제 #8
0
        public async Task AddSocialLogin(string userId, SocialLoginModel model)
        {
            var socialLogin = new SocialLogin
            {
                Name          = model.Name,
                Key           = model.Key,
                SocialLoginId = model.SocialLoginId,
                Provider      = model.Provider,
                UserId        = model.UserId
            };

            _context.Set <SocialLogin>().Add(socialLogin);
            await _context.SaveChangesAsync();

            model.SocialLoginId = socialLogin.SocialLoginId;
        }
예제 #9
0
        public async Task <bool> LoginAsync(SocialLoginModel model)
        {
            if (TryLogin())
            {
                return(true);
            }
            if (model == null)
            {
                return(false);
            }
            var user = await DependencyService.Get <IAuthentication>().LoginAsync(Client, model.Provider);

            Settings.AuthToken     = user?.MobileServiceAuthenticationToken;
            Settings.UserId        = user?.UserId;
            Settings.LoginProvider = ((int)model.Provider).ToString();

            return(Settings.IsLoggedIn);
        }
예제 #10
0
        //POST:  api/User/SocialLogin
        public async Task <IActionResult> SocialLogin([FromBody] SocialLoginModel model)
        {
            if (VerifyToken(model.Provider, model.IdToken))
            {
                model.UserName = model.Email.Split('@')[0];
                User user = await userManager.FindByNameAsync(model.UserName);

                if (user == null)
                {
                    // REGISTER
                    user = new User()
                    {
                        UserName  = model.UserName,
                        Email     = model.Email,
                        FirstName = model.FirstName,
                        LastName  = model.LastName
                    };

                    try
                    {
                        await userManager.CreateAsync(user);
                    }
                    catch (Exception ex)
                    {
                        return(BadRequest(new { message = ex.Message }));
                    }
                }

                //LOGIN
                string token = await TokenGenerator(user, "social");

                return(Ok(new { token }));
            }
            else
            {
                return(BadRequest(new { message = "Unable to authenticate." }));
            }
        }
예제 #11
0
 public async Task <IActionResult> SocialLogin([FromBody] SocialLoginModel model)
 {
     return(await MakeActionCallAsync(async() => await _tokenService.SocialLogin(model,
                                                                                 GetDeviceToken(), GetLanguage(), GetOsType(), GetDeviceId(), UserCurrency)));
 }
예제 #12
0
        public async Task <ActionResult> FaceBookLoginCheck([FromBody] SocialLoginModel data)
        {
            try
            {
                if (data.Token != null)
                {
                    string textResult;
                    using (var client = new HttpClient())
                    {
                        var uri = new Uri("https://graph.facebook.com/me?locale=en_US&fields=id,name&access_token=" + data.Token);

                        var response = await client.GetAsync(uri);

                        textResult = await response.Content.ReadAsStringAsync();
                    }
                    if (textResult.Contains("An active access token must be used to query information about the current user") || textResult.Contains("Malformed access token"))
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "402",
                            Message = "Invalid token",
                            Data = null
                        }));
                    }
                    else
                    {
                        var result    = Newtonsoft.Json.JsonConvert.DeserializeObject <FacebookVerificationModel>(textResult);
                        var checkUser = MH.CheckForDatas("SocialId", result.id, null, null, "Authentication", "Authentication");
                        if (checkUser == null)
                        {
                            return(Ok(new ResponseData
                            {
                                Code = "201",
                                Message = "User not found",
                                Data = null
                            }));
                        }
                        else
                        {
                            var        user       = BsonSerializer.Deserialize <RegisterModel>(checkUser);
                            Parameters parameters = new Parameters();
                            parameters.username = result.id;
                            parameters.fullname = user.FullName;;
                            return(Ok(Json(authHelper.DoPassword(parameters, _repo, _settings))));
                        }
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Token is empty",
                        Data = null
                    }));
                }
            }
            catch (Exception ex)
            {
                LoggerDataAccess.CreateLog("AuthController", "GoogleLogin", "GoogleLogin", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = null
                }));
            }
        }
예제 #13
0
        public async Task <ActionResult> GoogleLogin([FromBody] SocialLoginModel data)
        {
            try
            {
                if (data.Token != null)
                {
                    string textResult;
                    using (var client = new HttpClient())
                    {
                        var uri = new Uri("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + data.Token);

                        var response = await client.GetAsync(uri);

                        textResult = await response.Content.ReadAsStringAsync();
                    }
                    if (textResult.Contains("Invalid Value"))
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "402",
                            Message = "Invalid token",
                            Data = null
                        }));
                    }
                    else
                    {
                        var result = BsonSerializer.Deserialize <GoogleVerificationModel>(textResult);
                        if (result.sub == data.ID)
                        {
                            var checkUser = MH.CheckForDatas("UserName", result.email, null, null, "Authentication", "Authentication");
                            if (checkUser == null)
                            {
                                RegisterModel registerModel = new RegisterModel();
                                registerModel.UserName = result.email;
                                registerModel.SocialId = result.sub;
                                registerModel.FullName = result.name;
                                registerModel.Status   = "Verified";
                                registerModel.Email    = result.email;
                                var authCollection = _db.GetCollection <RegisterModel>("Authentication");
                                await authCollection.InsertOneAsync(registerModel);
                            }
                            Parameters parameters = new Parameters();
                            parameters.username = result.email;
                            parameters.fullname = result.name;;
                            return(Ok(Json(authHelper.DoPassword(parameters, _repo, _settings))));
                        }
                        else
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "403",
                                Message = "ID mismatch",
                                Data = null
                            }));
                        }
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Token is empty",
                        Data = null
                    }));
                }
            }
            catch (Exception ex)
            {
                LoggerDataAccess.CreateLog("AuthController", "GoogleLogin", "GoogleLogin", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = null
                }));
            }
        }