public ActionResult Login(LoginModel loginModel) { TokenRecieverModel token = GetToken(loginModel); Session["TokenKey"] = token.Token_type + " " + token.Access_token; return(RedirectToAction("Home", "VehicleRegistry")); }
private TokenRecieverModel GetToken(LoginModel loginModel) { TokenRecieverModel AccessToken = null; var httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = false, AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip }; var httpClient = new HttpClient(httpClientHandler); var stringContent = new StringContent(loginModel.GetTokenRequestString(), Encoding.UTF8, "application/x-www-form-urlencoded"); HttpResponseMessage tokenResponse = httpClient.PostAsync(endPoints.GetToken, stringContent).Result; { if (tokenResponse != null) { var jString = tokenResponse.Content.ReadAsStringAsync().Result; dynamic response = JsonConvert.DeserializeObject <dynamic>(jString); AccessToken = response.access_token; } return(AccessToken); } }