简体   繁体   English

Android 消费webservice的APP如何认证用户

[英]Android APP that consumes a webservice how to authenticate users

I'm developing an android app that consumes a webservice that I will develop too (I'm thinking in using a RESTFul webservice).. and I want to secure the connection between the app and the server but I need to authenticate users too..我正在开发一个 android 应用程序,它使用我将开发的 Web 服务(我正在考虑使用 RESTFul Web 服务)。我想保护应用程序和服务器之间的连接,但我也需要对用户进行身份验证。 .

My problem is in the last part, to secure the connection I think the best way to do it is to use SSL (https), am I wrong?我的问题在最后一部分,为了保护连接,我认为最好的方法是使用 SSL (https),我错了吗?

I don't know what's "the best way" to authenticate users, to make sure that a user cannot consume the webservice as another user.. I have some ideas, like using a authenticate(login,pass) method on the webservice that returns a token.. And for any operation that requires authentication the user would need to pass that token as a parameter.. The thing is, is this a good way to do this?我不知道对用户进行身份验证的“最佳方式”是什么,以确保用户不能将 web 服务作为另一个用户使用。我有一些想法,比如在返回的 web 服务上使用 authenticate(login,pass) 方法一个令牌..对于任何需要身份验证的操作,用户都需要将该令牌作为参数传递..问题是,这是一个好方法吗? whats the most common technique used to auth users in a situation like this?在这种情况下,用于对用户进行身份验证的最常用技术是什么?

If a token based auth is a good idea how should I generate the token?如果基于令牌的身份验证是一个好主意,我应该如何生成令牌?

Sorry for this long text..抱歉这么长的文字..

Any help will be usefull任何帮助都会很有用

Thanks谢谢

Make sure you understand a trendy standard like OAuth before you go down that path.确保您了解 go 之前的流行标准,例如 OAuth。 Most OAuth flows are centered around a user logging in to your server through a web browser.大多数 OAuth 流程以用户通过 web 浏览器登录到您的服务器为中心。 This can lead to pretty bad user experience for a mobile app.这可能会导致移动应用程序的用户体验非常糟糕。 The standard does allow for alternatives.该标准确实允许替代方案。 Here's a decent introduction .这是一个体面的介绍

You could also use an existing identity provider like Google, Facebook, Twitter, etc. instead of implementing your own authN/authZ.您还可以使用现有的身份提供商,例如 Google、Facebook、Twitter 等,而不是实现自己的 authN/authZ。 On Android, you can ask for a Google auth token using the AccountManager .在 Android 上,您可以使用AccountManager请求 Google 身份验证令牌。 This usually works because the user needs to be logged in to their Google account to access the Android Market.这通常有效,因为用户需要登录到他们的 Google 帐户才能访问 Android 市场。 Anyway, this will prompt the user to grant authorization to your app.无论如何,这将提示用户向您的应用授予授权。 You could then use the Google auth token to login your user to your service with your own token.然后,您可以使用 Google 身份验证令牌通过您自己的令牌将您的用户登录到您的服务。 The login would essentially be your server verifying the Google token is valid (by contacting Google's servers) and then issuing its own token to be used for calls to your web services.登录本质上是您的服务器验证 Google 令牌是否有效(通过联系 Google 的服务器),然后发出自己的令牌以用于调用您的 web 服务。 If you don't like Google, you could use the Facebook SDK , etc.如果你不喜欢谷歌,你可以使用Facebook SDK等。

As for what to use for tokens... The OAuth spec has stuff on that as well.至于令牌的用途...... OAuth 规范也有相关内容。 You could do something as simple as a random string or something as complex as encrypted SAML assertions .您可以做一些简单的事情,比如随机字符串,也可以做一些复杂的事情,比如加密的SAML 断言

You should implement a token based OAuth, which will require the users to log in once, and then permanently have access.您应该实施基于令牌的 OAuth,这将要求用户登录一次,然后永久拥有访问权限。

You can use Google App Engine which already provides user authentication services for you (your Android users most likely already have google accounts) But this is only one of many options.您可以使用已经为您提供用户身份验证服务的Google App Engine (您的 Android 用户很可能已经拥有 google 帐户)但这只是众多选项之一。

You can also look into Amazon's Identity Access Management (IAM) which will allow you to manage the users who have access to your web service, and authorize them accordingly.您还可以查看亚马逊的身份访问管理 (IAM) ,它允许您管理有权访问您的 web 服务的用户,并相应地授权他们。

I think the best way to do it is to use SSL (https), am I wrong?我认为最好的方法是使用 SSL (https),我错了吗?

This only prevents certain types of malicious use, but not everything.这只能防止某些类型的恶意使用,但不能防止一切。 There is still nothing to prevent people from accessing your database on the phone, and retrieving credentials that way.仍然没有什么可以阻止人们通过电话访问您的数据库,并以这种方式检索凭据。

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

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