title: JWT Authentication: Bearer token + Cookie
body: <p>I know this topic has been discussed many times, but there are so many articles around (and answers here in SO) that I'm a bit lost.
  My scenario is the following: I have a WebApi written in ASP.NET Core 6 and I want to authenticate a mobile PWA app written in VueJS, using JWT authentication.
  Reading through some articles and looking at the CheatSheet recommendations <a href="https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/JSON_Web_Token_for_Java_Cheat_Sheet.md#token-sidejacking" rel="nofollow noreferrer">here</a> and <a href="https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/JSON_Web_Token_for_Java_Cheat_Sheet.md#token-storage-on-client-side" rel="nofollow noreferrer">here</a>, this is what I have come up with:</p>
  <ol>
  <li>When I try to authenticate my user in the PWA, if the user credentials match, the server generates a token which contains also a claim with a &quot;fingerprint&quot;, a SHA256 encrypted random generated string. The same generated string is added in a dedicated cookie that is returned with the response to the client: the cookie has the <code>HttpOnly</code>, <code>Secure</code> and <code>SameSite</code> options enabled</li>
  <li>Once authenticated, I store the authToken and the refreshToken in my IndexedDb. First question here: <strong>why would I need to use a sessionStorage in my case when the user will never create a different session of my PWA anyway?</strong> NOTE: my token does NOT contain any user sensitive data</li>
  <li>Whenever I do a request from the PWA, with axios, I use the <code>withCredentials: true</code> option and I send to the server not only my token as a <code>Bearer</code> in the <code>Authorization</code> header, but also my fingerprint cookie</li>
  <li>For each request received, the server unpacks the token, checks its validity (issuer, audience, signature, expiration, etc.), but also checks that the fingerprint contained in the JWT claim matches the one in the received cookie</li>
  </ol>
  <p>So, from my understanding, the usage of this fingerprint guarantees that any XSS attack retrieving the token from the client storage won't be able to authenticate against my WebApi because it won't have the corresponding cookie. At the same time, the cookie is protected from XSRF attacks with the options I'm using for the cookie itself.</p>
  <p><strong>Is this correct? Is it strong enough?
  And also: can I simplify/enhance my algorithm by using the Antiforgery token built-in mechanism provided by ASP.NET Core?</strong></p>