Esempio n. 1
0
        public AuthenticateToken Authenticate(AuthenticateRequest request)
        {
            var user = _membershipService.GetUserByName(request.Name);

            if (user == null)
            {
                return(null);
            }

            var result = user.State == UserStates.Normal && string.Equals(User.SaltAndHash(request.Password, user.PasswordSalt), user.Password);

            if (result)
            {
                user.LastSignInTime = DateTime.Now;
                _membershipService.UpdateUser(user);
                var userRoles = _membershipService.QueryRoles(new RoleRequest()
                {
                    UserId = user.UserId
                }).ToList();
                var permissions = from x in userRoles
                                  from p in x.Permissions.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                                  select p;
                var token = new AuthenticateToken {
                    Name = request.Name, Roles = permissions.ToList(), Token = Guid.NewGuid().ToString()
                };
                _cacheManager.Add(request.Name, token);
                _cacheManager.Add(token.Name, request.Name);
                return(token);
            }
            return(null);
        }
Esempio n. 2
0
        public AuthenticateToken Authenticate(AuthenticateModel model)
        {
            var authToken    = new AuthenticateToken();
            var passwordHash = CreatePasswordHash(model.Password);
            var user         = _context.Users.FirstOrDefault(x => x.Email == model.Email && x.Password == passwordHash);

            // return null if user not found
            if (user == null)
            {
                return(null);
            }

            // authentication successful so generate jwt token
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(_appSettings.Secret);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, user.Id.ToString())
                }),
                // token expires in a day
                Expires            = DateTime.UtcNow.AddDays(1),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            authToken.Token     = tokenHandler.WriteToken(token);
            authToken.ValidFrom = token.ValidFrom;
            authToken.ValidTo   = token.ValidTo;

            return(authToken);
        }
        protected override void OnStart(string[] args)
        {
            // TODO: Add code here to start your service.

            token = AuthenticateToken.GetToken();

            Timer timer = new Timer();

            timer.Interval = 60000; // 60 seconds
            timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
            timer.Start();
        }
Esempio n. 4
0
        protected void GetAuthToken(OfficerToken token, string key, string newKey, string ip)
        {
            AuthenticateTokenMapDao _authenMap = new AuthenticateTokenMapDao();
            AuthenticateToken       Obj        = new AuthenticateToken();


            //_authenMap.AddOrUpdate(Obj);

            var objToken = _authenMap.FindActiveByAPIKey(key).ToList();

            foreach (var Items in objToken)
            {
                Items.Active = false;
                _authenMap.AddOrUpdate(Items);
                _authenMap.CommitChange();
            }
            //if (objToken.Count() > 0)
            //{
            //    //disable token
            //    foreach (var item in objToken)
            //    {
            //        if (item.Owner_ip == ip && Convert.ToDateTime(item.Process_date).AddMinutes(item.Process_time) > DateTime.Now)
            //        {
            //            token.Token_id = Encryption.Encrypt(item.Keygen);
            //        }
            //        else
            //        {
            //            item.Active = false;
            //            _authenMap.AddOrUpdate(item);
            //            _authenMap.CommitChange();
            //        }
            //    }
            //}

            //if (string.IsNullOrEmpty(token.Token_id))
            //{



            var authen = new AuthenticateToken(key, newKey, ip);

            _authenMap.AddOrUpdate(authen);
            _authenMap.CommitChange();
            token.Token_id = MyExtensions.ParamEncode(new { authen.ApiKey, Process_date = authen.Process_date.ToThaiFormateAndtime(), authen.Process_time, authen.Keygen });
            //token   =
            //}

            //_authenMap = null;
        }
Esempio n. 5
0
        public static List <DataTransferObject> GetData(string token)
        {
            DataTransferObject        result;
            List <DataTransferObject> results = new List <DataTransferObject>();

            string[] apiCalls = new[]
            {
                "equipment",
                "vehicle"
            };

            foreach (var apiCall in apiCalls)
            {
                var clientDestination = new RestClient("https://api-test.abax.cloud/v1/" + apiCall);

                var authentication = new JwtAuthenticator(token);
                clientDestination.Authenticator = authentication;

                var request  = new RestRequest(Method.GET);
                var response = clientDestination.Execute(request);

                if (response.IsSuccessful)
                {
                    response.Content = JValue.Parse(response.Content).ToString(Formatting.Indented);

                    result = new DataTransferObject();

                    result.data   = response.Content;
                    result.origin = apiCall;

                    results.Add(result);
                }
                else if (!response.IsSuccessful && getFailureCount <= 3)
                {
                    getFailureCount++;
                    AuthenticateToken.GetToken();
                }
            }
            return(results);
        }
Esempio n. 6
0
        private void RunButton_Click(object sender, EventArgs e)
        {
            progressBar1.Maximum = Convert.ToInt32(RunTimesValue.Text);
            progressBar1.Step    = 1;
            progressBar1.Update();


            var config1     = new Configurations();
            var spinRequest = new SpinRequest(this);
            var authToken   = new AuthenticateToken();

            spinRequest.Method = Verbs.GET;
            var pdata = spinRequest.PostData;

            var betReq = new BetRequest();

            String keysValue = KeyValue.Text;

            config1.TokenNames = KeyValue.Text.Split(',');
            string gamesType = comboBox1.SelectedIndex.ToString();

            var configs = authToken.AuthTokens(config1).Select(t => {
                var result        = new Configurations();
                result.TokenKey   = t;
                result.gameName   = GameValue.Text;
                result.TimeStamp  = TsValue.Text;
                result.multiplier = multiplier.Text;
                result.Bet        = BetValue.Text;
                result.GameType   = gamesType;
                result.RunTimes   = Int32.Parse(RunTimesValue.Text);

                return(result);
            });

            Parallel.ForEach(configs, (conf, state) => {
                spinRequest.SRequest(conf);
                System.Threading.Thread.Sleep(3000);
            }
                             );
        }