Ejemplo n.º 1
0
        protected override bool OnAuthorizeUser(string name, string password, HttpActionContext actionContext)
        {
            var provider = new TokenServices();

            if (provider != null)
            {
                Debug.WriteLine("Authenticating credentials - {0} {1}", name, password);
                ResponseWithToken token = provider.AuthenticateAsync(name, password).Result;
                Debug.WriteLine("Token - " + token);

                if (token != null)
                {
                    var basicAuthenticationIdentity = Thread.CurrentPrincipal.Identity as BasicAuthenticationIdentity;

                    if (basicAuthenticationIdentity != null)
                    {
                        basicAuthenticationIdentity.UserName = name;
                    }

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public async Task <ResponseWithToken> AuthenticateAsync(string userName, string password)
        {
            HttpContent       content;
            ResponseWithToken response;
            Payment           AuthUser = new Payment();

            AuthUser.loan_number = "";
            try
            {
                content = new FormUrlEncodedContent(new Dictionary <string, string> {
                    { "userID", userName }, { "password", password }, { "ssn", "" }
                });
                response = await API_Connection.PostAsync("/api/Auth/Authenticate", content);



                return(response);
            }
            catch (Exception Ex)
            {
                response = new ResponseWithToken();
                response.errorMessage = "Problem occurred trying to validate the user credentials. Please try again.";
                return(response);
            }
        }
Ejemplo n.º 3
0
        public async Task <ResponseModel> TestAuthAsync()
        {
            try
            {
                string returnedData = "";
                string tokenValue   = "";

                HttpContent content = new FormUrlEncodedContent(new Dictionary <string, string> {
                    { "userID", "0000100099" }, { "password", "Slloancare@1" }
                });
                ResponseWithToken response2 = await API_Connection.PostAsync("/api/Auth/Authenticate", content);

                tokenValue = response2.tokenValue;

                var response3 = await API_Connection.GetAsync(tokenValue, "/api/MyAccount/GetAccountInfo/0000100099");

                returnedData = await response3.Content.ReadAsStringAsync();

                return(new ResponseModel(returnedData));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public static async Task <HttpResponseMessage> DeleteAsync(string tokenValue, string url, HttpContent content)
        {
            ResponseWithToken returnData = new ResponseWithToken();
            Auth_GetToken     tokens     = await GetFormTokenAsync(tokenValue);

            var message = new HttpRequestMessage(HttpMethod.Delete, url);

            message.Headers.Add("Cookie", "locale=en-US; .lcauth=" + tokenValue);
            message.Headers.Add("cookieToken", tokens.cookieToken);
            message.Headers.Add("formToken", tokens.formToken);

            message.Content = content;
            var result = await client.SendAsync(message);

            result.EnsureSuccessStatusCode();

            if (result.Headers.TryGetValues("Set-Cookie", out IEnumerable <string> cookieValues))
            {
                string setCookieValue = HttpUtility.UrlDecode(cookieValues.FirstOrDefault());
                Regex  regex          = new Regex("lcauth=(.*?);");
                var    v = regex.Match(setCookieValue);
                if (v != null)
                {
                    returnData.tokenValue = v.Groups[1].ToString();
                }
            }

            return(returnData.message);
        }
Ejemplo n.º 5
0
        //Added by BBSR Team on 11th Jan 2018
        public static async Task <HttpResponseMessage> PostUserAsync(string url, HttpContent content)
        {
            ResponseWithToken returnData = new ResponseWithToken();
            Auth_GetToken     tokens     = await GetRegTokenAsync();

            var message = new HttpRequestMessage(HttpMethod.Post, url);

            message.Headers.Add("Cookie", "locale=en-US");
            message.Headers.Add("cookieToken", tokens.cookieToken);
            message.Headers.Add("formToken", tokens.formToken);
            message.Content = content;
            var result = await client.SendAsync(message);

            result.EnsureSuccessStatusCode();

            return(result);
        }
Ejemplo n.º 6
0
        private static async Task <Auth_GetToken> GetRegTokenAsync()
        {
            ResponseWithToken returnData = new ResponseWithToken();

            var message = new HttpRequestMessage(HttpMethod.Get, "/api/Register/GetToken/");

            message.Headers.Add("Cookie", "locale=en-US; .lcauth=");

            var response = await client.SendAsync(message);

            response.EnsureSuccessStatusCode();

            string returnedData = await response.Content.ReadAsStringAsync();

            Auth_GetToken tokenValues = JsonConvert.DeserializeObject <Auth_GetToken>(returnedData);

            return(tokenValues);
        }
Ejemplo n.º 7
0
        public static async Task <ResponseWithToken> GetDeletePaymentAsync(string tokenValue, string url)
        {
            ResponseWithToken returnData = new ResponseWithToken();

            returnData.errorId      = 0;
            returnData.errorMessage = "";
            var message = new HttpRequestMessage(HttpMethod.Get, url);

            message.Headers.Add("Cookie", "locale=en-US; .lcauth=" + tokenValue);
            var result = await client.SendAsync(message);


            if (result.IsSuccessStatusCode)
            {
                result.EnsureSuccessStatusCode();

                if (result.Headers.TryGetValues("Set-Cookie", out IEnumerable <string> cookieValues))
                {
                    string setCookieValue = HttpUtility.UrlDecode(result.Headers.GetValues("Set-Cookie").FirstOrDefault());
                    Regex  regex          = new Regex("lcauth=(.*?);");
                    var    v = regex.Match(setCookieValue);

                    if (v != null)
                    {
                        returnData.tokenValue = v.Groups[1].ToString();
                    }
                }
            }
            else
            {
                var responseAsString = await result.Content.ReadAsStringAsync();

                ErrorModel resultSet = JsonConvert.DeserializeObject <ErrorModel>(responseAsString);
                returnData.errorId      = resultSet.errorID;
                returnData.errorMessage = resultSet.message;
            }

            returnData.message = result;
            return(returnData);
        }
Ejemplo n.º 8
0
        public static async Task <ResponseWithToken> PostAsync(string url, HttpContent content)
        {
            ResponseWithToken returnData = new ResponseWithToken();

            var message = new HttpRequestMessage(HttpMethod.Post, url);

            message.Headers.Add("Cookie", "locale=en-US");
            message.Content = content;
            var result = await client.SendAsync(message);

            returnData.errorId            = 0;
            returnData.tokenValue         = "";
            returnData.errorMessage       = "";
            returnData.changePassword     = "******";
            returnData.authenticateResult = new Authenticate();

            if (result.IsSuccessStatusCode)
            {
                result.EnsureSuccessStatusCode();

                if (result.Headers.TryGetValues("Set-Cookie", out IEnumerable <string> cookieValues))
                {
                    string setCookieValue = HttpUtility.UrlDecode(result.Headers.GetValues("Set-Cookie").FirstOrDefault());
                    Regex  regex          = new Regex("lcauth=(.*?);");
                    var    v = regex.Match(setCookieValue);

                    var responseAsString = await result.Content.ReadAsStringAsync();

                    returnData.tokenValue = v.Groups[1].ToString();

                    if (responseAsString.Contains("loanPaid"))
                    {
                        Authenticate resultSet = JsonConvert.DeserializeObject <Authenticate>(responseAsString);
                        if (resultSet.objUserInfo.user.changePassword == "Y")
                        {
                            returnData.authenticateResult = resultSet;
                            returnData.authenticateResult.AuthorizationToken = v.Groups[1].ToString();
                            returnData.changePassword = "******";
                        }
                    }
                    else
                    {
                        ErrorModel contentError = JsonConvert.DeserializeObject <ErrorModel>(responseAsString);
                        returnData.errorId      = 1;
                        returnData.errorMessage = contentError.msg;
                    }
                    returnData.message = result;
                }
                else
                {
                    var responseAsString = await result.Content.ReadAsStringAsync();

                    ErrorModel resultSet = JsonConvert.DeserializeObject <ErrorModel>(responseAsString);
                    returnData.errorId      = 1;
                    returnData.errorMessage = resultSet.msg;
                }
            }
            else
            {
                var responseAsString = await result.Content.ReadAsStringAsync();

                ErrorModel resultSet = JsonConvert.DeserializeObject <ErrorModel>(responseAsString);
                returnData.errorId      = resultSet.errorID;
                returnData.errorMessage = resultSet.message;
            }

            return(returnData);
        }