SHARE
TWEET

Untitled

a guest Jun 25th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. _factory = new WebApplicationFactory<MyWebApi.Startup>();
  2.         _client = _factory.CreateClient();
  3.  
  4.         _client.DefaultRequestHeaders.Clear();
  5.         _client.DefaultRequestHeaders.Accept.Clear();
  6.         _client.DefaultRequestHeaders.Accept.Add(
  7.          new MediaTypeWithQualityHeaderValue("application/json"));
  8.         _client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");
  9.         var content = new FormUrlEncodedContent(new[]
  10.         {
  11.             new KeyValuePair<string, string>("username", "userABC"),
  12.             new KeyValuePair<string, string>("password","password123")
  13.         });
  14.  
  15.         var response = await _client.PostAsync("/account/login", content);
  16.      
  17. [HttpPost]
  18.     [AllowAnonymous]
  19.     [Route("login")]
  20.     public async Task<object> Login(string userName, string password)
  21.     {
  22.         try
  23.         {
  24.             var result = await _signInManager.PasswordSignInAsync(userName, password, false, false);
  25.             if (result.Succeeded)
  26.             {
  27.                 var appUser = _userManager.Users.SingleOrDefault(r => r.UserName == userName);
  28.                 return GenerateJwtToken(userName, appUser);
  29.             }
  30.             else
  31.             {
  32.                 return BadRequest(new { message = "No user found! Please check user name and password." });
  33.             }
  34.         }
  35.         catch (Exception ex)
  36.         {
  37.             return StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError, ex.Message);
  38.         }
  39.     }
  40.      
  41. public async Task<object> Login([FromBody]MyPostModel model)
  42. {
  43.    ...
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top