我想使用JWT令牌来确保请求是由Android应用程序发送的。因此,我在登录到服务器(PHP)时发送一个POST请求,服务器返回一个存储在Android设备上的JWT令牌。对于与API通信的其余部分,我将发送带有请求的JWT令牌,以确保API请求被允许。然而,我不确定如何识别用户。
识别用户的推荐方式是什么?我不确定将用户id作为有效负载存储在JWT令牌中是否合适。关于隐私问题,什么是最好的方式?
发布于 2021-10-31 00:09:38
编辑:我说胡扯(见评论) :)
我(自认为)通常做的事情是:
发出登录请求
- Server creates a JWT associated with the corresponding user
- Server stores it, associated to the corresponding user
- Server sends it back to the client
- Client stores the JWT
发出api调用以查询资源。
- Server authenticates the user (as the one which is linked to this JWT)
- Server do authorization checks for this user and this ressource
- Server appropriately do actions and send ressources
这样,您就不需要在JWT本身中存储用户id。
然而,我同意上面的评论:我不确定用户知道他们的id的事实可能是一个隐私问题。如果这是一个安全问题,那么它不仅是一个问题,而且是一个安全漏洞。
https://stackoverflow.com/questions/69784918
复制