Exemplo n.º 1
0
        async Task oAuthLogin(User user)
        {
            //Authenticate against ADFS and NW Gateway
            oAuthLogin oauthlogin = new oAuthLogin();

            user.Username = user.Username + "@jkintranet.com";
            String access_token = await oauthlogin.LoginUserAsync(user);


            if ((access_token != "" && access_token != Constants._userNotExistInNWGateway) && access_token != Constants._gatewayUrlError)
            {
                //Store Username and Password in global Area
                Constants._user = user;

                //Store Username and Password in local shared preference
                Settings.Username = user.Username;
                Settings.Password = user.Password;

                //Retrieving Hotel Code
                try
                {
                    await hotelInformationAndLogin();
                }
                catch (Exception)
                {
                    await DisplayAlert(Constants._headerConnectionLost, Constants._networkerror, Constants._buttonOkay);
                }
            }
            else if (access_token == Constants._gatewayUrlError)
            {
                await DisplayAlert(Constants._headerConnectionLost, Constants._gatewayUrlError, Constants._buttonOkay);
            }
            else
            {
                if (access_token == Constants._userNotExistInNWGateway)
                {
                    await DisplayAlert(Constants._headerMessage, Constants._userNotExistInNWGateway, Constants._buttonClose);
                }
                else
                {
                    await DisplayAlert(Constants._headerWrongCredentials, Constants._incorrectlogincredentials, Constants._buttonClose);
                }
            }


            stopLoading();
        }
Exemplo n.º 2
0
        //public async Task<string> GetAttachments(string fileType)
        //{

        //    //Refresh Token if expires
        //    if (Convert.ToDateTime(Settings.ExpiresTime) <= DateTime.Now)
        //    {
        //        //Authenticate against ADFS and NW Gateway
        //        oAuthLogin oauthlogin = new oAuthLogin();
        //        String access_token = await oauthlogin.LoginUserAsync(Constants._user);
        //        if (access_token == "" && access_token == Constants._userNotExistInNWGateway)
        //        {
        //            userLogout.logout();
        //        }
        //    }

        //    //string url = $"https://jkhapimdev.azure-api.net/api/beta/v1/getattachments/getReservationAttachmentSet?$filter=IXhotelId eq '{Constants._hotel_code}' and IXreservaId eq '{Constants._reservation_id}' and IXtype eq '{fileType}'"; //Dev
        //    string url = $"https://octopus.keells.lk/api/v1/getattachments/getReservationAttachmentSet?$filter=IXhotelId eq '{Constants._hotel_code}' and IXreservaId eq '{Constants._reservation_id}' and IXtype eq '{fileType}'";

        //    using (var client = new HttpClient())
        //    {
        //        client.BaseAddress = new Uri(url);
        //        // Request headers
        //        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants._access_token);
        //        //client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "7ab76f2c1d7b41c3b6c07a0d2ee492c3");//DEV
        //        client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "dbaee796a5fe47bf8f4c467cd7cf9d4d");
        //        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


        //        var response = await client.GetAsync(url);
        //        using (HttpContent content = response.Content)
        //        {
        //            string result = await content.ReadAsStringAsync();
        //            return result;
        //        }
        //    }
        //}

        public async Task <String> GetODataService(String url)
        {
            try
            {
                //Refresh Token if expires
                if (Convert.ToDateTime(Settings.ExpiresTime) <= DateTime.Now)
                {
                    //Authenticate against ADFS and NW Gateway
                    oAuthLogin oauthlogin   = new oAuthLogin();
                    String     access_token = await oauthlogin.LoginUserAsync(Constants._user);

                    if (access_token == "" && access_token == Constants._userNotExistInNWGateway)
                    {
                        userLogout.logout();
                    }
                }
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Constants._gatewayURL + url);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants._access_token);
                    try
                    {
                        HttpResponseMessage response = await client.GetAsync(Constants._gatewayURL + url);

                        using (HttpContent content = response.Content)
                        {
                            string result = await content.ReadAsStringAsync();

                            return(result);
                        }
                    }
                    catch (Exception e)
                    {
                        return("Error");
                    }
                }
            }
            catch (Exception e)
            {
                return("Error");
            }
        }
Exemplo n.º 3
0
        public async Task <string> GetAttachments(string fileType)
        {
            //Refresh Token if expires
            if (Convert.ToDateTime(Settings.ExpiresTime) <= DateTime.Now)
            {
                //Authenticate against ADFS and NW Gateway
                oAuthLogin oauthlogin   = new oAuthLogin();
                String     access_token = await oauthlogin.LoginUserAsync(Constants._user);

                if (access_token == "" && access_token == Constants._userNotExistInNWGateway)
                {
                    userLogout.logout();
                }
            }

            //string url = $"https://jkhapimdev.azure-api.net/api/beta/v1/getattachments/getReservationAttachmentSet?$filter=IXhotelId eq '{Constants._hotel_code}' and IXreservaId eq '{Constants._reservation_id}' and IXtype eq '{fileType}'"; //Dev
            string url = $"https://cheetah.azure-api.net/api/v1/getattachments/getReservationAttachmentSet?$filter=IXhotelId eq '{Constants._hotel_code}' and IXreservaId eq '{Constants._reservation_id}' and IXtype eq '{fileType}'";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(url);
                // Request headers
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants._access_token);
                //client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "7ab76f2c1d7b41c3b6c07a0d2ee492c3");//DEV
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "dbaee796a5fe47bf8f4c467cd7cf9d4d");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                var response = await client.GetAsync(url);

                using (HttpContent content = response.Content)
                {
                    string result = await content.ReadAsStringAsync();

                    return(result);
                }
            }
        }
Exemplo n.º 4
0
        public async Task <string> GetProformaInvoiceNumber(String url, String postBody)
        {
            string xcsrf_token  = "";
            string cookie_value = "";

            try
            {
                //Refresh Token if expires
                if (Convert.ToDateTime(Settings.ExpiresTime) <= DateTime.Now)
                {
                    //Authenticate against ADFS and NW Gateway
                    oAuthLogin oauthlogin   = new oAuthLogin();
                    String     access_token = await oauthlogin.LoginUserAsync(Constants._user);

                    if (access_token == "" && access_token == Constants._userNotExistInNWGateway)
                    {
                        userLogout.logout();
                    }
                }

                CookieContainer   cookies = new CookieContainer();
                HttpClientHandler handler = new HttpClientHandler();
                handler.CookieContainer = cookies;

                using (var client = new HttpClient(handler))
                {
                    //Get X-CSRF-TOKEN
                    client.BaseAddress = new Uri(Constants._gatewayURL + url);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants._access_token);
                    client.DefaultRequestHeaders.Add("x-csrf-token", "fetch");

                    //GET data
                    HttpResponseMessage response = await client.GetAsync(Constants._gatewayURL + url);

                    xcsrf_token = response.Headers.GetValues("X-CSRF-Token").FirstOrDefault();

                    Uri uri = new Uri(Constants._gatewayURL + url);
                    IEnumerable <Cookie> responseCookies = cookies.GetCookies(uri).Cast <Cookie>();
                    foreach (Cookie cookie in responseCookies)
                    {
                        if (Constants._cookie == cookie.Name)
                        {
                            cookie_value = cookie.Value;
                        }
                    }
                }

                if (xcsrf_token != "" && cookie_value != "")
                {
                    //Post Method
                    Uri baseUri = new Uri(Constants._gatewayURL + url);
                    HttpClientHandler clientHandler = new HttpClientHandler();
                    //Set Cookie in Post
                    clientHandler.CookieContainer.Add(baseUri, new Cookie(Constants._cookie, cookie_value));

                    using (var client_post = new HttpClient(clientHandler))
                    {
                        client_post.BaseAddress = new Uri(Constants._gatewayURL + url);
                        client_post.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants._access_token);
                        client_post.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        //Set Token in Post
                        client_post.DefaultRequestHeaders.Add("X-CSRF-Token", xcsrf_token);

                        //Post json content
                        var response = client_post.PostAsync(Constants._gatewayURL + url, new StringContent(postBody, Encoding.UTF8, "application/json")).Result;
                        if (response.IsSuccessStatusCode)
                        {
                            Debug.WriteLine(response);
                            var perRes = response.Content.ReadAsStringAsync();
                            Debug.WriteLine(perRes.Result);
                            return(perRes.Result);
                        }
                        else
                        {
                            return(await response.Content.ReadAsStringAsync());
                        }
                    }
                }
                else
                {
                    return("Token or cookie is not available");
                }
            }
            catch (Exception e)
            {
                return("Error");
            }
        }
Exemplo n.º 5
0
        public async Task <string> GetODataAzureService(string url, string postBody)
        {
            string xcsrf_token  = "";
            string cookie_value = "";

            try
            {
                //Refresh Token if expires
                if (Convert.ToDateTime(Settings.ExpiresTime) <= DateTime.Now)
                {
                    //Authenticate against ADFS and NW Gateway
                    oAuthLogin oauthlogin = new oAuthLogin();

                    string access_token = await oauthlogin.LoginUserAsync(Constants._user);

                    if (access_token == "" && access_token == Constants._userNotExistInNWGateway)
                    {
                        userLogout.logout();
                    }
                }

                CookieContainer   cookies = new CookieContainer();
                HttpClientHandler handler = new HttpClientHandler();
                handler.CookieContainer = cookies;

                using (var client = new HttpClient(handler))
                {
                    //Get X-CSRF-TOKEN
                    //client.BaseAddress = new Uri(Constants._azureAPIMDEVBase + url);//DEV
                    client.BaseAddress = new Uri(Constants._azureAPIMPRDBase + url);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants._access_token);
                    client.DefaultRequestHeaders.Add("X-CSRF-Token", "fetch");
                    //client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "7ab76f2c1d7b41c3b6c07a0d2ee492c3");//DEV
                    client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "dbaee796a5fe47bf8f4c467cd7cf9d4d");

                    //GET data
                    //HttpResponseMessage response = await client.GetAsync(Constants._azureAPIMDEVBase + url);//DEV
                    HttpResponseMessage response = await client.GetAsync(Constants._azureAPIMPRDBase + url);

                    xcsrf_token = response.Headers.GetValues("X-CSRF-Token").FirstOrDefault();

                    //Uri uri = new Uri(Constants._azureAPIMDEVBase + url);//DEV
                    Uri uri = new Uri(Constants._azureAPIMPRDBase + url);
                    IEnumerable <Cookie> responseCookies = cookies.GetCookies(uri).Cast <Cookie>();
                    foreach (Cookie cookie in responseCookies)
                    {
                        if (Constants._cookie == cookie.Name)
                        {
                            cookie_value = cookie.Value;
                        }
                    }
                }

                if (xcsrf_token != "" && cookie_value != "")
                {
                    //Post Method
                    //Uri baseUri = new Uri(Constants._azureAPIMDEVBase + url);//DEV
                    Uri baseUri = new Uri(Constants._azureAPIMPRDBase + url);
                    HttpClientHandler clientHandler = new HttpClientHandler();
                    //Set Cookie in Post
                    clientHandler.CookieContainer.Add(baseUri, new Cookie(Constants._cookie, cookie_value));

                    using (var client_post = new HttpClient(clientHandler))
                    {
                        //client_post.BaseAddress = new Uri(Constants._azureAPIMDEVBase + url);//DEV
                        client_post.BaseAddress = new Uri(Constants._azureAPIMPRDBase + url);
                        client_post.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants._access_token);
                        client_post.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        //Set Token in Post
                        client_post.DefaultRequestHeaders.Add("X-CSRF-Token", xcsrf_token);
                        //client_post.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "7ab76f2c1d7b41c3b6c07a0d2ee492c3");//DEv
                        client_post.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "dbaee796a5fe47bf8f4c467cd7cf9d4d");

                        //Post json content
                        //var response = client_post.PostAsync(Constants._azureAPIMDEVBase + url, new StringContent(postBody, Encoding.UTF8, "application/json")).Result;//DEV
                        var response = client_post.PostAsync(Constants._azureAPIMPRDBase + url, new StringContent(postBody, Encoding.UTF8, "application/json")).Result;
                        if (response.IsSuccessStatusCode)
                        {
                            Debug.WriteLine(response);
                            return("success");
                        }
                        else
                        {
                            return(await response.Content.ReadAsStringAsync());
                        }
                    }
                }
                else
                {
                    return("Token or cookie is not available");
                }
            }
            catch (Exception e)
            {
                return("Error");
            }
        }