static async Task <string> GetToken(string url, string username, string password, string apikey) { string token = string.Empty; using (HttpClient client = new HttpClient()) { TokenRequestor tokenRequest = new TokenRequestor(apikey, username, password); string JSONresult = JsonConvert.SerializeObject(tokenRequest); HttpContent c = new StringContent(JSONresult, Encoding.UTF8, "application/json"); HttpResponseMessage message = await client.PostAsync(url, c); string tokenJSON = await message.Content.ReadAsStringAsync(); string pattern = "token\":\"([a-z0-9]*)"; Regex myRegex = new Regex(pattern, RegexOptions.IgnoreCase); Match m = myRegex.Match(tokenJSON); String string_m = m.ToString(); char[] chars = { ':' }; string[] matches = string_m.Split(chars); string final_match = matches[1].Trim(new Char[] { '"' }); token = final_match; } return(token); }
public ActionResult InputToken(string username, string password) { string token = ""; try { var tr = new TokenRequestor(username, password); token = tr.GetAuthToken(); } catch (WebException ex) { ModelState.AddModelError("password", ex); return(RedirectToIndex(ex.Message)); } CurrentItem.Token = token; Engine.Persister.Save(CurrentItem); return(Redirect(CurrentPage.Url)); }
/// <summary> /// Initializes a new instance of the <see cref="ReportRequestor"/> class. /// </summary> public ReportRequestor() { _tokenRequestor = new TokenRequestor(); }