예제 #1
0
파일: Steps.cs 프로젝트: summitn/Ocelot
        public void GivenIHaveAnOcelotToken(string adminPath)
        {
            var tokenUrl = $"{adminPath}/connect/token";
            var formData = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("client_id", "admin"),
                new KeyValuePair <string, string>("client_secret", "secret"),
                new KeyValuePair <string, string>("scope", "admin"),
                new KeyValuePair <string, string>("username", "admin"),
                new KeyValuePair <string, string>("password", "admin"),
                new KeyValuePair <string, string>("grant_type", "password")
            };
            var content = new FormUrlEncodedContent(formData);

            var response        = _ocelotClient.PostAsync(tokenUrl, content).Result;
            var responseContent = response.Content.ReadAsStringAsync().Result;

            response.EnsureSuccessStatusCode();
            _token = JsonConvert.DeserializeObject <BearerToken>(responseContent);
        }
예제 #2
0
파일: Steps.cs 프로젝트: zhikecore/Ocelot
        public void GivenIHaveATokenForApi2(string url)
        {
            var tokenUrl = $"{url}/connect/token";
            var formData = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("client_id", "client"),
                new KeyValuePair <string, string>("client_secret", "secret"),
                new KeyValuePair <string, string>("scope", "api2"),
                new KeyValuePair <string, string>("username", "test"),
                new KeyValuePair <string, string>("password", "test"),
                new KeyValuePair <string, string>("grant_type", "password")
            };
            var content = new FormUrlEncodedContent(formData);

            using (var httpClient = new HttpClient())
            {
                var response        = httpClient.PostAsync(tokenUrl, content).Result;
                var responseContent = response.Content.ReadAsStringAsync().Result;
                response.EnsureSuccessStatusCode();
                _token = JsonConvert.DeserializeObject <BearerToken>(responseContent);
            }
        }