Exemple #1
0
        public async Task <SessionToken> GetSessionToken(LoginArgs loginArgs, HttpClient httpClient)
        {
            //httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            string encode = GetBase64Encoding(string.Format($"{loginArgs.key}:{loginArgs.password}"));

            GetSessionArgs getSessionArgs = new GetSessionArgs()
            {
                password = encode,
                userId   = loginArgs.userId
            };

            HttpContent httpContent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(getSessionArgs), Encoding.UTF8, "application/json");


            HttpResponseMessage httpResponseMessage = await httpClient.PostAsync("/apiauth/1.0.0/services/auth/login", httpContent);

            if (httpResponseMessage.IsSuccessStatusCode)
            {
                var temp = await httpResponseMessage.Content.ReadAsStringAsync();

                var result = Newtonsoft.Json.JsonConvert.DeserializeObject <SessionToken>(temp);
                return(result);
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        private async Task <HttpClient> GenerateHttpClient()
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("https://apidemo.epitomeais.com");

            // get access
            var identity = await GetAccess(client);

            client.DefaultRequestHeaders.Add("Authorization", string.Format($@"Bearer {identity.access_token}"));
            // get session
            LoginArgs loginArgs = new LoginArgs()
            {
                password = "******",
                key      = "VertExMQU5X6dTda",
                userId   = "VERTEXPPFT01"
            };
            var sessionToken = await GetSessionToken(loginArgs, client);

            client.DefaultRequestHeaders.Add("SessionToken", sessionToken.results);
            //client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            return(await Task.FromResult(client));
        }