Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to secure a REST API for mobile applications?

I am trying to add a REST interface to Django for a mobile client. The mobile client will use JSON over HTTPS. I have not been able to find the "best" way to accomplish this for mobile devices. From searching around, it seems that #2 is more favorable to #1:

  1. Use HTTP authentication and establish a cookie based session. All transactions will occur over HTTP and JSON messages will only contain commands or data.
  2. Pass the username and password (encrypted) within each JSON msg for all transactions and do not rely on cookie-based sessions.
like image 508
ewhitt Avatar asked Feb 29 '12 22:02

ewhitt


1 Answers

I would recommend sending the username / password first with a login call. The JSON will pass back an authToken or accessToken which the mobile device will send back for all subsequent calls. You will then check to make sure the authToken is valid. This is the approach many API's take. In their database they will bind the API key to the users account that they logged in with.

like image 71
Bot Avatar answered Sep 21 '22 20:09

Bot