예제 #1
0
        public static Response GetTokenInfo()
        {
            var url2    = @$ "{GlobalData.HostApi}/api/authenticate/tokeninfo";
            var headers = new Dictionary <string, string>
            {
                { "Authorization", $"Bearer {GlobalData.UserToken?.Token}" }
            };

            try
            {
                var response = WebRequestHelper.GetResponseString(url2, "GET", null, "application/json", headers);
                return(JsonConvert.DeserializeObject <Response>(response));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #2
0
        private bool GetUser(string login, string pass)
        {
            var url       = @$ "{GlobalData.HostApi}/api/authenticate/login";
            var body      = @"{""username"": ""UserName"", ""password"": ""Password@123""}";
            var userToken = WebRequestHelper.GetResponseString(url, "POST", body, "application/json");

            GlobalData.UserToken = JsonConvert.DeserializeObject <UserToken>(userToken);
            var tokenInfo = ApiClient.GetTokenInfo();

            if (tokenInfo?.Status == "Success")
            {
                System.IO.File.WriteAllText(@"C:\Temp\UserToken.txt", userToken);
                return(tokenInfo?.Status == "Success");
            }
            return(false);



            //////var token = @"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVXNlck5hbWUiLCJqdGkiOiI2MjI5NDdlMS1iZGZjLTRjYjMtOTdhOC1kZGMxYjg3MjlhZjciLCJleHAiOjE2MTI5OTcwMTEsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.QCTsQqW8O7Pkw71zMZVk3nukiUKaUanx6XdIF6aePhM";
            //////var url2 = @"https://localhost:44359/weatherforecast";
            //////var headers = new Dictionary<string, string>
            //////{
            //////    { "Authorization", $"Bearer {token}" }
            //////};
            //////try
            //////{
            //////    var test2 = WebRequestHelper.GetResponseString(url2, "GET", null, "application/json", headers);
            //////}
            //////catch (Exception ex)
            //////{
            //////    throw;
            //////}


            //List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>
            //{
            //    new KeyValuePair<string, string>("1","2")
            //};
            //return keyValuePairs.Any(x => x.Key == login && x.Value == pass);
        }