title: Login via HttpClient
body: <p>I am using this code to consume ASP.NET MVC 5 WebAPI2.</p>
  
  <pre><code>static async Task RunAsync()
          {
              using (var client = new HttpClient())
              {
                 client.BaseAddress = new Uri("http://localhost:52967/");
                  client.DefaultRequestHeaders.Accept.Clear();
                  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
                  // New code:
                  HttpResponseMessage response = await client.GetAsync("api/Account/Login");
                  if (response.IsSuccessStatusCode)
                  {
                      var data = await response.Content.ReadAsStringAsync();
  
                  }
              }
          }
  </code></pre>
  
  <p>Under <code>AccountController</code> I created following method </p>
  
  <pre><code>[HttpPost]
          [AllowAnonymous]
          [Route("Login")]
          public HttpResponseMessage Login(string username, string password)
          {
              try
              {
                  var identityUser = UserManager.Find(username, password);
  
                  if (identityUser != null)
                  {
                      var identity = new ClaimsIdentity(Startup.OAuthOptions.AuthenticationType);
                      identity.AddClaim(new Claim(ClaimTypes.Name, username));
  
                      AuthenticationTicket ticket = new AuthenticationTicket(identity, new AuthenticationProperties());
                      var currentUtc = new SystemClock().UtcNow;
                      ticket.Properties.IssuedUtc = currentUtc;
                      ticket.Properties.ExpiresUtc = currentUtc.Add(TimeSpan.FromMinutes(1440));
  
                      var token = Startup.OAuthOptions.AccessTokenFormat.Protect(ticket);
  
                      var response = new HttpResponseMessage(HttpStatusCode.OK)
                      {
                          Content = new ObjectContent&lt;object&gt;(new
                          {
                              UserName = username,
                              ExternalAccessToken = token
                          }, Configuration.Formatters.JsonFormatter)
                      };
  
                      return response;
  
  
                  }
              }
              catch (Exception)
              {
              }
  
              return new HttpResponseMessage(HttpStatusCode.BadRequest);
          }
  </code></pre>
  
  <p>I need to pass username and password somehow. Any clue?</p>