Search code examples
javaspring-securityfacebook-oauthspring-socialspring-social-facebook

Not receiving first name, last name and surname from Facebook OAuth


Lately I have inherited a spring application from another developer which uses Spring Social and Spring Security to authenticate the user.

Because the developer who wrote it wants to discontinue his App Id on Facebook, I created a new one. And this is when the problem started.

I changed the app id and app secret to my new ones and suddenly by signing up, the Facebook stopped delivering first name, last name and e-mail address.

At the beginning I thought it might be because of my new Facebook user who is also the owner of the new app id but no. The app is still running productive with the old app id and when I sign up with my user the aforementioned attributes are delivered.

What am I missing here? Do I have to switch something magical when defining my Facebook application on developers.facebook.com?

The new application is activated and available to the general public. The Site URL and app domains are set as well as Valid OAuth redirect URIs.

I am currenlty trying to test the application on localhost and so are the domains set in the Facebook app settings.

The instance of org.springframework.social.connect.UserProfile returns the name of the user if I use getName(), however getFirstName(), getLastName() and getEmail() are all returning null.


Solution

  • The problem was indeed the fact that the old Facebook app used Graph API version lower than 2 and it worked perfectly with the spring-social-facebook package version 1.1.0.

    If one wants to create a new Facebook app it is not possible any longer to do it with Graph API 1.x.

    The solution was to upgrade spring-social-facebook package to version 2.0.2 and to change the following piece of coding from

    @Bean
    public ProviderSignInUtils providerSignInUtils() {
        return new ProviderSignInUtils();
    }
    

    to

    @Bean
    public ProviderSignInUtils providerSignInUtils(
            final ConnectionFactoryLocator connectionFactoryLocator,
            final UsersConnectionRepository usersConnectionRepository) {
        return new ProviderSignInUtils(connectionFactoryLocator,
                usersConnectionRepository);
    }