简体   繁体   English

如何确定哪个用户正在从Android应用程序发出Rest请求?

[英]How to determine which user is making Rest requests from android application?

I am trying to build a Spray REST Web server for my mobile application on android (Eventually Iphones too). 我正在尝试为android(最终也是iPhone)上的移动应用程序构建Spray REST Web服务器。 Currently, I am wondering how to determine from the server side which user is making REST Method requests. 当前,我想知道如何从服务器端确定哪个用户正在发出REST方法请求。 After some research I am understanding that android's SharedPreferences or an OAuth protocol can be utilized to handle user authentication. 经过一些研究,我了解到可以使用android的SharedPreferences或OAuth协议来处理用户身份验证。 Still I am unsure how to create the entire picture of "This user is requesting some information". 我仍然不确定如何创建“此用户正在请求某些信息”的整个图片。 The message responses will be in JSON text, should the request's be in JSON as well? 消息响应将采用JSON文本格式,请求的响应也应采用JSON格式吗?

I greatly appreciate all of your help, eagerly awaiting responses. 我非常感谢您的所有帮助,并期待着您的回复。

Currently, I am wondering how to determine from the server side which user is making REST Method requests. 当前,我想知道如何从服务器端确定哪个用户正在发出REST方法请求。

The most adequate way to do this is to add auth layer to your server. 最合适的方法是向服务器添加身份验证层。 There are many ways of how exactly you can do this, depending on security concerns you have to deal with. 有多种方法可以精确地做到这一点,这取决于您必须处理的安全问题。

Here is the list of auth schemes I would be looking into first of all: 这是我首先要考虑的身份验证方案的列表:

  • Http basic auth (most simple one, stick with it if you can) Http基本身份验证 (最简单的一种,如果可以,请坚持使用)
  • OpenID or OAuth (harder to implement, solves some problems that are out of scope of simply authenticating user. Note: OAuth is about authorization but can also be used to do authentication) OpenID或OAuth (难以实现,解决了一些简单验证用户身份范围之外的问题。注意:OAuth与授权有关,但也可以用于进行验证)
  • home-gown auth (may be implemented on different network layers, lots of options here. Do not recommend going here unless you really need to). 本地身份验证 (可能在不同的网络层上实现,这里有很多选择。除非确实需要,否则建议不要在这里进行)。

You can send more info from client side when user send request, you include unique info (Android ID, Ads ID for example) 您可以在用户发送请求时从客户端发送更多信息,其中包括唯一信息(例如,Android ID,Ads ID)

server.address/request?command=abc&uid=UID...

. Another way is read IP address of the user and manage it by session. 另一种方法是读取用户的IP地址并通过会话对其进行管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM