android - 使用 Google + Facebook 登录的 Android 应用程序的 Spring boot REST api 安全性

标签 android spring-boot spring-security android-facebook android-security

我正在构建一个具有 2 层的应用程序:-

<强>1。 native Android 应用程序 - 包含通过 Facebook + Google 登录的功能,以减轻登录的痛苦。

<强>2。使用 Spring Boot 的 Java 服务器 - 典型的 MVC 端点,例如 REST api + UI 管理屏幕。

Facebook ( FacebookSdk ) 和谷歌 ( GoogleApiClient ) 登录部分正在使用以下 Android 依赖项进行工作和测试:-

dependencies {
   compile 'com.facebook.android:facebook-android-sdk:4.6.0'
   compile 'com.google.android.gms:play-services-auth:9.0.0'
   ....

}

在 API 方面我们有:-

/api/signin - called when a user signs in successfully with either Facebook + Google and creates an entry in a users database table.

还有许多其他 API 端点,例如优惠

/api/offers/<user_id> - returns offers to an already registered user.

我不确定最佳实践方式:-

  1. Android 应用程序如何对 /api/signin REST 端点进行 API 调用(即哪些 header 等可以发送到我认为是端点的没有安全性 因为未注册的用户会点击这个)。另外,哪些字段可以保存在 users 中数据库表?

  2. Android 应用程序如何执行 API 调用,例如/api/offers/ 给已经注册的用户?即,Android 应用应在何时传递 token 等?

  3. Spring Security 保护这些端点的最佳实践方法。

假设 OAuth 2 是要走的路,但任何建议/指示将不胜感激。

最佳答案

Ans:1/api/signin 在登录应用程序时会将用户信息发送到服务器,服务器将生成 token 并且此 token 将在登录时返回应用程序可以保存此 token 它可以不时更改。 您可以将任何 http 库用于 web 服务,例如 volley、Retrofit 等。

您需要存储在数据库中的字段:userId、userName、userToken。

Ans:2/api/offers/你可以在数据库中检查用户的 userId,如果它存在,那么你将抛出 msg 已经存在于网络服务响应中。

Ans:3 为您的 Web 服务使用 SSL 实现会更加安全,正如您所提到的,您将为每个用户使用 token ,只有经过身份验证的用户才能访问它。

注意:- token 应每 30 分钟或您希望的任何时间更改,这将使您的身份验证功能更加安全。

关于android - 使用 Google + Facebook 登录的 Android 应用程序的 Spring boot REST api 安全性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41829831/

相关文章:

java - 使用 :if and th:replcae in thymeleaf 动态更改页面

java - Spring Security 3.1.1 - 自定义登录成功问题

Android VideoView 不工作

javascript - 托管的 JS 文件未加载到 android webview 中

android - 在 Android Studio 中创建图片资源

java - kubernetes:无法拉取图像

android - 调整 TextView 的大小不会在 Android 3.1 上缩小其高度

java - spring boot 如何使用 src/test/resource/中的 yaml 文件 Autowiring bean

java - Cxf Web服务设计问题

spring - 使用 Grails Spring Security Rest 插件时出现不够范围错误