hardikm9850 / Go-Playground

1 stars 0 forks source link

Why Access Tokens are Passed in Headers, Not Body? #5

Open hardikm9850 opened 1 month ago

hardikm9850 commented 1 month ago

Security

Visibility: Headers are typically not logged or displayed in browser history, reducing the risk of exposure.

Other Considerations

Idempotency: Some HTTP methods (like GET) are idempotent, meaning they can be repeated without changing the result. Passing tokens in the body could lead to unintended consequences if a request is retried.  

Content-Type:

Request bodies often have specific content types (e.g., JSON, XML), while headers are agnostic. In summary, passing JWTs in headers provides a secure, efficient, and standardized approach to authentication.

By placing the access token in the header, we ensure that it is processed before the request body, and it is less likely to be intercepted or tampered with.