Handling Sessions on Google App Engine with Android/IPhone

前端 未结 6 521
借酒劲吻你
借酒劲吻你 2021-02-04 07:11

I\'m starting to write an app whereby a mobile app (Android/IPhone) will communicate with the GAE backend (Python) through a series of Web API calls using JSON.

I can\'t

6条回答
  •  野的像风
    2021-02-04 07:33

    There are many ways to do this.

    1) When you check the users login details if it checks out you can then create a random UUID or string and store the User object in memcache with the random string as the Key and the User Object as the value. Then return the random string along with your response headers. On the mobile when you are parsing the response, get this header and store it in the local cache. On all further requests keep sending this key back in the request header and in your controller get the User object from memcache using this key and proceed. If the object is not in memcache you can send back a response which prompts the user to log in.

    2) If you dont want to use memcache you can store the User object in the session and on the client side while parsing the response get the session id from the response. Its usually JSESSIONID. Then store that and resend it with further requests. In the controller you can check if the current session has the user object else force login.

    1) Another way to go would be to return the appengine key for the user along with the response and resend it.

    Just google get response header from response. Then get the SESSIONID/JSESSIONID header, store and add the field with the same name and value to all further request headers. Thats the easiest way.

    My first answer on stackoverflow and no code exapmles, dangit if only i knew python.

提交回复
热议问题