user's email is always NULL - Spring Social Facebook Login

Viewed 4034

According to Facebook's official documentation, email access is given to any app provided user accepts and grants permission when login using Facebook.

I've double checked our app definition and I can see email should be accessible.

enter image description here

I'm using the latest available from Spring Social

<spring-social-security>1.1.4.RELEASE</spring-social-security>
<spring-social-core>1.1.4.RELEASE</spring-social-core>
<spring-social-facebook>2.0.3.RELEASE</spring-social-facebook>

Users successfully login using Facebook as a provider as well as Google+ and Twitter.

Unfortunately for all cases email is NULL except for my own user.

There are two scenarios where email could be null though

  • if someone signed up for Facebook with a phone number instead of an email address, the email field may be empty
  • This field will not be returned if no valid email address is available

I've triple checked that by accessing a friend's of mine account which

  1. It's got a valid email verified
  2. It's got a phone number associated with it
  3. We are friends with each other
  4. His phone and email are visible for his friends

I go to the GraphApi explorer but no email is ever returned.

Any advice? Thank you.

3 Answers

As @felipe mentioned, it required to set permission/scope to get email during facebook login in spring social.

If you are using XML format instead of java class for config then you can be defined scope as follow.

 <bean id="connectionFactoryRegistry"
              class="org.springframework.social.security.SocialAuthenticationServiceRegistry">
            <property name="authenticationServices">
                <util:list>
                    <bean class="org.springframework.social.facebook.security.FacebookAuthenticationService">
                        <constructor-arg value="${facebook.clientId}"/>
                        <constructor-arg value="${facebook.clientSecret}"/>
                        <property name="defaultScope" value="email"/>
                    </bean>
                </util:list>
            </property>
        </bean>
        <alias name="connectionFactoryRegistry" alias="connectionFactoryLocator"/>

I spent a few hours to find a way to set'scope' via XML config. so posting solution here that can be helpful to others.

Ref:-https://github.com/timeu/GWA-Portal/blob/c4fffb0cc4aeb295d9eef7c642c7a25090560014/genophenbrowser-server/src/main/resources/META-INF/spring-social.xml

Related