There are a ton of articles explaining what CSRF is and that I should use a CSRF token to prevent CSRF. A few of them mention details such as using SHA256 over MD5. However, none of them explain how to implement CSRF protection in relation to the user flow. For example, am I suppose to store the CSRF token in a database or can it be self contained? Here's how I think I'm going to implement CSRF protection, let me know if there's anything wrong:
User arrives at the page and logs in. They receive an http-only cookie containing a JWT.
I generate a random 128-512 bit value (fixed length, I will decide how long it is). Then, I concat the value and the user's ID and HMAC SHA256 hash the result with a private key. I embed both the random value and the hash in the HTML.
Whenever the user makes an API request, the random value and the hash are appended as either a header, GET variable, or POST variable (there's no difference to security right?).
The server concats the given value with the user's ID and compares it with the given hash. If they match, then the CSRF portion is done.
Is this implementation correct? Some cause for concern is that the user receives a new CSRF token every time they perform a full page load. They can also have multiple valid tokens if they have multiple tabs open. I don't think these will cause issues though.
Edit: A whole day of reading about CSRF later, I realized I can just put the JWT in the API request header and that's it.