title: Does SignInAsync have the ability to create jwt like how it does for cookies? And whether to avoid using SignInAsycn when using JWT auth?
body: <p>I have a project with .NET Identity tables and SignIn and User manager. The <code>SignInManager.PasswordSignInAsync</code> checks whether the username and password is correct and if so then it will create the cookie as part of the response. Currently the authentication configured is the default cookie based.</p>
  <p>Following is the existing example of <code>login</code> action:</p>
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
  public async Task&lt;ActionResult&gt; Login(LoginViewModel model, string returnUrl)
  {
      if (!ModelState.IsValid)
      {
          return View(model);
      }
  
      // Require the user to have a confirmed email before they can log on.
      var user = await UserManager.FindByNameAsync(model.Email);
   
      // This doesn't count login failures towards account lockout
      // To enable password failures to trigger account lockout, change to shouldLockout: true
      var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
      switch (result)
      {
          case SignInStatus.Success:
              return RedirectToLocal(returnUrl);
          case SignInStatus.Failure:
          default:
              ModelState.AddModelError(&quot;&quot;, &quot;Invalid login attempt.&quot;);
              return View(model);
      }
  }
  </code></pre>
  <p>I want to change this to JWT based and for this I plan to create the following:</p>
  <ol>
  <li>GetUserFromDb(username, password) - this will be called instead of <code>SignInManager.PasswordSignInAsync</code> and it will check in the db if the user exists and return the user details</li>
  <li>CreateJWT(userdetails) - the output of point 1 will be passed into this method as an argument and this method will build the JWT token with user name, and all the claims. This will returned to the user (that is - the caller of the login endpoint).</li>
  <li>Change the authentication scheme in startup to JWT bearer based, so that the authentication middleware can create the User identity based on the data inside the JWT token passed by the user in the authorization bearer header.</li>
  </ol>
  <p>Instead of doing any of the above manual work, I want to ask-</p>
  <ol>
  <li>Suppose I change the authentication scheme to JWT bearer based, then does <code>SignInManager.PasswordSignInAsync</code> have the ability to return a JWT (without me having to create the additional methods mentioned above) rather than the cookie?</li>
  <li>During User registration, I can continue using <code>var result = await UserManager.CreateAsync(user, model.Password);</code> - that is - to create the user in the database. But during login does it make sense to use <code>SignInManager.PasswordSignInAsync</code> (to check user/password) and then call the <code>GetUserFromDb</code> (to return user info) followed by <code>CreateJWT</code> (to set JWT)? Or should I prefer to not use the <code>SignInManager.PasswordSignInAsync</code>?</li>
  <li>Does <code>SignInManager.PasswordSignInAsync</code> have any relation to the authentication scheme? For example - does it create cookie in the response only if the authentication scheme is default (cookie based) or does it do so even if the Authentication scheme is changed to JWT bearer based? In this case it doesn't make sense to use <code>SignInManager.PasswordSignInAsync</code> when doing a JWT based authentication?</li>
  </ol>