Spring social - Facebook cant authenticate

801 views Asked by At

I trying to implement Spring social to signin with Facebook or other social network.

I doing some wrong, but i dont know what is it.

When I do the request to facebook in the log I see the 200 (OK) but I cant get the logged user.

I the logs I see:

First I see facebook returning the user:

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}"

But after the request I see:

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

When I look in my database in the table "UserConnection" I don't see the user.

Also when I try to get the principal user always is anonymous.

I dont know where is the error or where class I need to modify or create. I can put all the code.

Thanks in advance. Stel.

1

There are 1 answers

0
steve On BEST ANSWER

Are you using SpringSocialConfigurer? Are you simply calling the "/auth/{provider}"?

My guess is that you have the following issue:

You successfully signed in via facebook, however

  • you do not have an existing userconnection with an existing local user
  • you do not have a local user and need to establish a connection with a provider

You can do a few things to test

  • try the signup approach using ProviderSigninController or
  • try to set to Implicit signin / signup. it will create new local user if non is found.

See this good tutorial

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