I'm building a very simple API using silex (php micro-framework). I have an idea on how to authenticate user using Facebook connect or username / password.
I want to build this API to provide data to my mobile app. My API is using HTTPS. The authentication with Facebook:
- Facebook Connect happen on the mobile app
- The mobile app is sending the user token and facebook_id to the API
- The API check the user Facebook id requesting
/me?token=...
- The API check the Facebook app_id is correct
/app?token=...
- -> The user does exists and is authenticated
Now using login / password:
- the mobile app send the username and encoded password
- The API check the combinaison is correct
- -> The user does exists and is authenticated
The question is about the user session. I don't really want to do this tests on every requests (ie. for Facebook auth there is 2 requests to Facebook).
I was thinking to open a session for the user and store some kind of API token. The token would be hashed and salted (salt + user_id + time delivered). I would store it in the session table and would only need to check that the token is still valid and belong to the requesting user.
So the mobile app would only send the user id + the api token for every request.
What to you think of it ? Do you thing of a better solution keeping it simple? Or do you see any issue with this design?
Cheers, Maxime