简体   繁体   English

Android facebook登录Spring Social webapp

[英]Android facebook signin for Spring Social webapp

I'm currently developing a web application with Spring Social and Spring Security. 我目前正在使用Spring Social和Spring Security开发一个Web应用程序。 In the web application, specific users can signin on Facebook with ProviderSignInController . 在Web应用程序中,特定用户可以使用ProviderSignInController在Facebook上登录。 When staff members authenticate with FB successfully, they are programatically signed in for my local webapp with Spring Security, too. 当工作人员成功通过FB进行身份验证时,他们也会以编程方式登录我的Spring Security本地Web应用程序。 This concept is adapted from the spring-social-showcase . 这个概念改编自春季社交展示 Spring Social then enables authenticated users to create Events, which are also created on a facebook page. Spring Social然后允许经过身份验证的用户创建事件,这些事件也是在Facebook页面上创建的。

Now i want to write a android app which enables users to post to my guestbook and view/create events via my web application. 现在我想写一个Android应用程序,它允许用户发布到我的留言簿,并通过我的Web应用程序查看/创建事件。 My question now is how to realize the signin from my andoid app. 我现在的问题是如何从我的andoid应用程序中实现登录。 On my web application, a UsersConnectionRepository maps facebook accounts to local accounts. 在我的Web应用程序中, UsersConnectionRepository将facebook帐户映射到本地帐户。 Can i simply reuse this data and signin from my android app in the exact same way as from the web application? 我可以简单地重用这些数据并从我的Android应用程序中以与从Web应用程序完全相同的方式登录吗? ProviderSignInController adds a path mapping for http://_webapp_/signin/facebook which redirects to a facebook signin page. ProviderSignInControllerhttp://_webapp_/signin/facebook添加路径映射,重定向到facebook登录页面。 Can this simply be done with a WebView on android? 这可以简单地在Android上使用WebView完成吗?

Looking on the spring-android-facebook-client im confused. 看着spring-android-facebook-client我很困惑。 This example seems to manually manage the OAuth authentication. 此示例似乎手动管理OAuth身份验证。 But i havent figured out yet, whether this is the way to go or just another possibility to implement it, when there is no other web application in the background that already manages the authentication. 但我还没想到,当后台中没有其他已经管理认证的Web应用程序时,这是实现它的方式还是另一种可能性。

Any feedback is welcome. 欢迎任何反馈。 Thanks. 谢谢。

Jeyp Jeyp

Now i want to write a android app which enables users to post to my guestbook and view/create events via my web application. 现在我想写一个Android应用程序,它允许用户发布到我的留言簿,并通过我的Web应用程序查看/创建事件。

The Android client will need a method to sign in to your web application in order to post to a secured RESTful endpoint, and OAuth is a good method for doing this. Android客户端需要一种方法来登录您的Web应用程序,以便发布到安全的RESTful端点,OAuth是一种很好的方法。 Spring Security OAuth is an extension of Spring Security that can allow third party mobile or web clients to interact with your web site. Spring Security OAuth是Spring Security的扩展,可以允许第三方移动或Web客户端与您的网站进行交互。

Once you have an OAuth server configured, you can create a custom provider using Spring Social within your Android client to establish an OAuth connection to your web site. 配置OAuth服务器后,您可以在Android客户端中使用Spring Social创建自定义提供程序,以建立与您的网站的OAuth连接。 Your users will authenticate to your web site with their local credentials in this case. 在这种情况下,您的用户将使用其本地凭据对您的网站进行身份验证。 Once connected, your Android app can then post events to RESTful endpoints within your web site, again using your custom Spring Social API bindings. 连接后,您的Android应用程序可以再次使用您的自定义Spring Social API绑定将事件发布到您网站中的RESTful端点。

In this scenario, your users do not authenticate to Facebook from the Android application. 在这种情况下,您的用户不会从Android应用程序向Facebook进行身份验证。 This assumes they have already established an account and a connection to Facebook on your web site. 这假设他们已经在您的网站上建立了帐户和Facebook连接。 And in fact, this is how the SpringSource Greenhouse reference application works. 事实上,这就是SpringSource Greenhouse参考应用程序的工作原理。

This brings us back to a previous part of your question: 这将我们带回到您问题的前一部分:

When staff members authenticate with FB successfully, they are programatically signed in for my local webapp with Spring Security, too. 当工作人员成功通过FB进行身份验证时,他们也会以编程方式登录我的Spring Security本地Web应用程序。

If I understand correctly, you are asking to authorize your Android client to access your third-party web site, with Facebook credentials. 如果我理解正确,您要求授权您的Android客户端使用Facebook凭据访问您的第三方网站。 While this is certainly possible, it is not currently supported through Spring Social and Spring for Android. 虽然这当然是可能的,但目前尚未通过Spring Social和Spring for Android支持。

Another option is to consider a mobile version of your web site. 另一种选择是考虑您的网站的移动版本。 That way Android and other mobile devices can then simply sign in to your site just like from a normal browser, using their Facebook credentials. 这样,Android和其他移动设备就可以使用他们的Facebook凭据简单地从普通浏览器登录到您的网站。 The UI would be more appropriate for mobile devices, and it would eliminate the extra complexity of an additional OAuth server/client configuration. 用户界面更适合移动设备,它可以消除额外OAuth服务器/客户端配置的额外复杂性。

And finally, to address the last part of your question. 最后,要解决问题的最后部分。 This is really a separate issue from the previous parts: 这与前面的部分实际上是一个单独的问题:

This example seems to manually manage the OAuth authentication. 此示例似乎手动管理OAuth身份验证。

The primary issue is that Spring Social does not yet support Resource Owner Credentials Grant (ROCG). 主要问题是Spring Social尚不支持资源所有者凭证授权(ROCG)。 The addition of this feature would simplify the process of obtaining an access token for Facebook on Android, because you would not have to deal with a browser redirection. 添加此功能将简化在Android上获取Facebook访问令牌的过程,因为您不必处理浏览器重定向。 See this Spring Social issue for more information. 有关更多信息,请参阅此Spring社会问题

Because of the lack of ROCG, the Spring for Android sample app is illustrating one method for obtaining the access token using Spring Social. 由于缺乏ROCG,Spring for Android示例应用程序演示了一种使用Spring Social获取访问令牌的方法。 In this case, it is a modified version of the client-side authentication flow. 在这种情况下,它是客户端身份验证流程的修改版本。 For reference, Facebook has a helpful page describing all the available authentication methods . 作为参考,Facebook有一个有用的页面,描述了所有可用的身份验证方法 The webview redirects to a url after successful authentication, at which point the app is able to retrieve the access token from this url. 成功验证后,webview会重定向到网址,此时应用可以从此网址中检索访问令牌。

SpringSource is discussing how to simplify authentication and improve this part of the integration between Spring Social and Spring for Android in future releases. SpringSource正在讨论如何在未来版本中简化身份验证并改进Spring Social和Spring for Android之间的这一部分集成。

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

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