I am working on an iOS application which communicates with a nodejs backend server REST API and I am thinking about API authentication.
I want that only the iOS application can communicate with the API.
On iOS application side, users are authenticated through Facebook login. They thus get a fb access_token and a fbid after authentication on the iOS app.
For the API authentication, I plan to make it this way:
- When the user logs in into the iOS app, a call to /api/auth with his fb access_token and fbid is done;
- If the user is new, I create a random api_token for this user, store it into Users DB, and send it back to the iOS app;
- If the user is already in the DB, I refresh the fb access_token in my DB and the api_token and send it back to the iOS app;
- For each API call, I give the api_token as a POST parameter and on server side I check if it is valid by fetching in the DB before executing the API call.
Am I missing something to be enough secured?
Any feedback or improvement will be very welcome.
Regards,
EDIT:
Another way would be the following:
- On /api/auth I checked on FacebookB API (/me) if the fb access_token is still valid;
- If not I refuse the authentication;
- If yes I create and manage my api_token with JSON Web Tokens.