[英]Android with Django: How to keep user logged in
I want to know what the method used by popular apps are. 我想知道热门应用程序使用的方法是什么。
Here are the approaches I have considered: 以下是我考虑过的方法:
I don't think you should store user credentials in preferences. 我认为您不应该在首选项中存储用户凭据。
The most common approach is to send credentials to server and then as a response get a session key. 最常见的方法是将凭据发送到服务器,然后作为响应获取会话密钥。 Then include the session key as a header to any request (and validate it in every request).
然后将会话密钥作为任何请求的标头包含(并在每个请求中对其进行验证)。
If the session key would become invalid (eg expired) then the server should return a proper response, and the client should initialize authentication functionality. 如果会话密钥变为无效(例如,过期),则服务器应返回适当的响应,并且客户端应初始化认证功能。
Egzample Egzample
First run 首轮
Activity
Activity
session_key
as a response (normally its a hash) session_key
作为响应(通常是哈希) session_key
hash session_key
哈希 Activity
Activity
Any request to the server. 对服务器的任何请求。
session_key
to your request (eg as a header) session_key
添加到您的请求中(例如作为标题) First run
First run
First run 首轮
For other request. 对于其他要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.