0

我试图实现 Spring social 以使用 Facebook 或其他社交网络登录。

我做错了,但我不知道是什么。

当我在日志中向 facebook 发出请求时,我看到了200 (OK)但我无法获取已登录的用户。

我看到的日志:

首先,我看到 facebook 返回用户:

2014-11-19T14:18:48.156+0100|Info: http-outgoing-1 << "{"id":"***","first_name":"***","gender":"male","last_name":"***","link":"https:\/\/www.facebook.com\/app_scoped_user_id\/***\/","locale":"es_ES","name":"***","timezone":2,"updated_time":"2014-03-20T21:50:00+0000","verified":true}"

但是在请求之后我看到:

2014-11-19T14:18:48.164+0100|Info: GET request for "https://graph.facebook.com/me" resulted in 200 (OK)
2014-11-19T14:18:48.165+0100|Info: Reading [class org.springframework.social.facebook.api.FacebookProfile] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@3ee8e5cb]
2014-11-19T14:18:48.165+0100|Info: Connection [id: 1][route: {s}->https://graph.facebook.com:443] can be kept alive indefinitely
2014-11-19T14:18:48.165+0100|Info: Connection released: [id: 1][route: {s}->https://graph.facebook.com:443][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 10]
2014-11-19T14:18:48.198+0100|Info: Authentication attempt using org.springframework.social.security.SocialAuthenticationProvider
2014-11-19T14:18:48.220+0100|Info: Executing prepared SQL query
2014-11-19T14:18:48.223+0100|Info: Executing prepared SQL statement [select userId from UserConnection where providerId = ? and providerUserId = ?]
2014-11-19T14:18:48.243+0100|Info: Fetching JDBC Connection from DataSource
2014-11-19T14:18:48.288+0100|Info: Returning JDBC Connection to DataSource
2014-11-19T14:18:48.298+0100|Info: Authentication request failed: org.springframework.social.security.SocialAuthenticationRedirectException:
2014-11-19T14:18:48.299+0100|Info: Updated SecurityContextHolder to contain null Authentication
2014-11-19T14:18:48.299+0100|Info: Delegating to authentication failure handler org.springframework.social.security.SocialAuthenticationFailureHandler@20cc9603
2014-11-19T14:18:48.299+0100|Info: SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
2014-11-19T14:18:48.300+0100|Info: SecurityContextHolder now cleared, as request processing completed

当我在“UserConnection”表中查看我的数据库时,我看不到用户。

另外,当我尝试获取主要用户时,始终是匿名的。

我不知道错误在哪里或我需要修改或创建的类。我可以把所有的代码。

提前致谢。斯蒂尔。

4

1 回答 1

0

你在使用 SpringSocialConfigurer 吗?您只是调用“/auth/{provider}”吗?

我的猜测是你有以下问题:

但是,您已通过 facebook 成功登录

  • 您没有与现有本地用户的现有用户连接
  • 您没有本地用户,需要与提供商建立连接

你可以做一些事情来测试

  • 尝试使用 ProviderSigninController 的注册方法或
  • 尝试设置为隐式登录/注册。如果未找到,它将创建新的本地用户。

看到这个好教程

http://www.petrikainulainen.net/programming/spring-framework/adding-social-sign-in-to-a-spring-mvc-web-application-configuration/

于 2015-03-17T23:06:29.860 回答