Пример #1
0
        public async Task <ApiResponse <LoginDetail> > ReAuthenticateUser(string refreshToken, string ipAddress)
        {
            var response       = new ApiResponse <LoginDetail>();
            var tokenPartition = refreshToken.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            if (tokenPartition.Length < 2)
            {
                response.Success = false;
                response.ErrorMesssage.Add(MtsResource.RefreshTokenNotValid);
            }

            if (response.Success)
            {
                try
                {
                    tokenPartition[0] = tokenPartition[0].Replace(" ", "+");
                    var chip = _crypto.DecryptString(tokenPartition[0], _config.EncryptionKey);
                    if (_crypto.CheckMatch(tokenPartition[1], chip))
                    {
                        var userCred = chip.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                        if (userCred.Length == 2)
                        {
                            response = await this.AuthenticateUser(new UserLogin
                            {
                                Email     = userCred[0],
                                Password  = userCred[1],
                                IpAddress = ipAddress
                            });
                        }
                        else
                        {
                            response.Success = false;
                            response.ErrorMesssage.Add(MtsResource.RefreshTokenNotValid);
                        }
                    }
                }
                catch (Exception e)
                {
                    response.Success = false;
                    response.ErrorMesssage.Add(MtsResource.RefreshTokenNotValid);
                }
            }
            return(response);
        }