private async Task GivenIHaveAnOcelotToken(string adminPath) { async Task <bool> AddToken() { try { 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>("grant_type", "client_credentials") }; var content = new FormUrlEncodedContent(formData); var response = await _httpClient.PostAsync(tokenUrl, content); var responseContent = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { return(false); } _token = JsonConvert.DeserializeObject <BearerToken>(responseContent); var configPath = $"{adminPath}/.well-known/openid-configuration"; response = await _httpClient.GetAsync(configPath); return(response.IsSuccessStatusCode); } catch (Exception) { return(false); } } var addToken = await Wait.WaitFor(40000).Until(async() => { var result = await AddToken(); Thread.Sleep(1000); return(result); }); addToken.ShouldBeTrue(); }
private 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", "secret"), new KeyValuePair <string, string>("grant_type", "password") }; var content = new FormUrlEncodedContent(formData); var response = _httpClient.PostAsync(tokenUrl, content).Result; var responseContent = response.Content.ReadAsStringAsync().Result; response.EnsureSuccessStatusCode(); _token = JsonConvert.DeserializeObject <BearerToken>(responseContent); }
private void GivenIHaveAToken(string url) { var formData = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("client_id", "api"), new KeyValuePair <string, string>("client_secret", "secret"), new KeyValuePair <string, string>("scope", "api"), 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($"{url}/connect/token", content).Result; var responseContent = response.Content.ReadAsStringAsync().Result; response.EnsureSuccessStatusCode(); _token = JsonConvert.DeserializeObject <BearerToken>(responseContent); } }