There are three options:
I haven't done too much work with authentication but am building an API that will need it. What I have done previously is parse the API key (e.g sha-256) in the body of a post request.
But I have just realised that you can't do this with GET requests, right? So I need to find the most secure way of authenticating each API request.
I was thinking, would it be more secure to pass the user's authenticationkey
(which is stored in the users database table) as well as an oAuth key with each request? This way any hacker would need two keys to get into the system?
How should I go about this?
To authenticate every request, would I have the router check each request for an API key?
Sort of like this:
app.all('/api/v1/*', [require('./middlewares/validateRequestAPIKEY')]);
I had design few API for the mobile applications and following is what I have implemented for my clients:
The Keys will be passed in header
On server side I will check for keys on each API call for validation, in some API you might need to skip the validation (login is one example)
Here are my implementations
1) Token/keys expiration is not required:
2) When token requires expiration:
Hope that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With