r/developersIndia • u/phenixdhinesh • May 05 '25
Tips How Do You Send Refresh Tokens — Headers or Request Body?
Hey folks!
Got into a debate with a friend while working on our app’s authentication — specifically, how to send refresh tokens to the backend:
- In headers (
Authorization: Bearer <token>) - Or in the request body (
{ refresh_token: "<token>" })
After some digging, we found a solid reason to go with the request body:
➡️ Refresh tokens are long-lived and sensitive
➡️ Headers can be logged by proxies or servers, increasing exposure risk
➡️ Payloads (bodies) give better control and align with security best practices
What started as a quick argument turned into a valuable learning experience about API security.
💬 So now I'm curious — have you had similar moments while developing?
Times where a casual decision turned into a deep dive that changed how you approach best practices?
Would love to hear your stories and what you've learned along the way. Let's swap lessons!
•
u/AutoModerator May 05 '25
It's possible your query is not unique, use
site:reddit.com/r/developersindia KEYWORDSon search engines to search posts from developersIndia. You can also use reddit search directly.Recent Announcements
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/rohit720 Software Developer May 05 '25
In my case we had two token, a
Bearer Tokenand arefresh token. We saverefresh tokenin redis with a TTL of 30 days. This validrefresh tokenis used to generate aBearer tokenwhen it expires [ 30min ]. We send refresh token in request header. WhenBearer Tokengets expired while making an api call a newBearer Tokenis generated and also we rotate therefresh tokenand send this in the response header back.36
u/the2ndfloorguy Backend Developer May 05 '25
Adding my 2 cents to it
A cleaner way to impl this is to have a dedicated
POST /refreshendpoint that handles token refresh logic. Typically, I've seen people sending both access and refresh tokens in headers with every request. I get that, it takes a bit of effort to set up a proper access ↔ refresh token flow. Testing is easier that way, and you don't have to pause the actual request while fetching a new token.But yeah same as your points, ideally you should:
It's a bit more work, but pays off long-term.
3
u/_L3NZ_ May 05 '25
Access tokens-> headers Refresh tokens -> api to create tokens; in body
8
u/[deleted] May 05 '25
[removed] — view removed comment