32
How to store user's access tokens/API keys without hashing them?
(lemmy.pe1uca.dev)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
Neat. I can help with some of these concepts:
You can protect your Basic Auth password simply by storing it in cleartext where it is needed with reasonable protections
(This is again assuming your use case is actually okay for not having OAuth. If it's health data, suck it up and do real OAuth, obviously.)
Reasonable protections for your Basic Auth passwords:
In summary:
Happy sailing!
Edit: Also, practice replacing the secret, ideally with automation - and preferrably do so every 90 days.
Edit 2: Make that password as long as heck and meaningless. No one needs to memorize this thing. Generate it random, long and meaningless, paste it in two places, and forget about it for 90 days.
Edit 3: Deliver this secret to your end user over the phone (spoken to a human, not a text message). Do so every 90 days. When they complain, ask them if they're interested in OAuth now.
Thanks for all the information and advises!
So in theory basic auth is enough when sent through HTTPS, right?
If this is the case then the user would need to handle their password and my API can keep storing just the hash.
In another comment JWT was suggested, maybe this could also be a solution?
I'm thinking the user can worry about generating and signing the token and we could only be storing the public key , which requires less strictness when handling it, this way we can validate the token has been signed by who we expect and the user will worry about the private key.
Yes. Don't put nuclear weapons, health data or huge sums of money behind it, but basic Auth has been doing a fine job for a lot of things for a long time, and HTTPS is a complete solution (until the next time it gets owned).
Yep. The hard part is securely delivering the generated secret to them. And making sure that, the shorter and less random that secret is, the more often it gets replaced. For a lot of not-too-sensitive use cases, a phone call and a long random secret will do the job.
JWT is a fantastic solution, and probably the first thing you want to upgrade to if your use case needs more than Basic Auth.
That makes sense. Note that many popular JWT libraries will do a lot of that for you.