title: Spring social facebook + spring security permission to email and username scope
body: <p>I want to integrate Spring Social facebook into my application with Spring Security (I use annotation base configurations). All I need is just connect facebook account with my app's account. In simple example I found this:</p>
  
  <pre><code>package eu.thinking4u.spring.social.simple.signinmvc.config;
  
  import javax.sql.DataSource;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.core.env.Environment;
  import org.springframework.security.crypto.encrypt.Encryptors;
  import org.springframework.social.UserIdSource;
  import org.springframework.social.config.annotation.ConnectionFactoryConfigurer;
  import org.springframework.social.config.annotation.EnableSocial;
  import org.springframework.social.config.annotation.SocialConfigurer;
  import org.springframework.social.connect.ConnectionFactoryLocator;
  import org.springframework.social.connect.ConnectionRepository;
  import org.springframework.social.connect.UsersConnectionRepository;
  import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;
  import org.springframework.social.connect.web.ConnectController;
  import org.springframework.social.facebook.connect.FacebookConnectionFactory;
  import org.springframework.social.security.AuthenticationNameUserIdSource;
  
  
  @Configuration
  @EnableSocial
  public class SocialContext implements SocialConfigurer {
  
      @Autowired
      private DataSource dataSource;
  
      /**
       * Configures the connection factories for Facebook and Twitter.
       * @param cfConfig
       * @param env
       */
      public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
         /* cfConfig.addConnectionFactory(new TwitterConnectionFactory(
                  env.getProperty("twitter.consumer.key"),
                  env.getProperty("twitter.consumer.secret")
          ));*/
          /*cfConfig.addConnectionFactory(new FacebookConnectionFactory(
                  env.getProperty("facebook.app.id"),
                  env.getProperty("facebook.app.secret")
  
          ));*/
          final FacebookConnectionFactory fbcf = new FacebookConnectionFactory(env.getProperty("facebook.app.id"),
                  env.getProperty("facebook.app.secret"));
                  fbcf.setScope("email");
                  cfConfig.addConnectionFactory(fbcf);
         }
  
      /**
       * The UserIdSource determines the account ID of the user. The example application
       * uses the username as the account ID.
       */
      public UserIdSource getUserIdSource() {
          return new AuthenticationNameUserIdSource();
      }
  
      public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
          return new JdbcUsersConnectionRepository(
                  dataSource,
                  connectionFactoryLocator,
                  /**
                   * The TextEncryptor object encrypts the authorization details of the connection. In
                   * our example, the authorization details are stored as plain text.
                   * DO NOT USE THIS IN PRODUCTION.
                   */
                  Encryptors.noOpText()
          );
      }
  
      /**
       * This bean manages the connection flow between the account provider and
       * the example application.
       */
      @Bean
      public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) {
          return new ConnectController(connectionFactoryLocator, connectionRepository);
      }
  
  /*    @Bean
      public CanvasSignInController canvasSignInController(ConnectionFactoryLocator connectionFactoryLocator,
              UsersConnectionRepository usersConnectionRepository, Environment env)
      {
          return new CanvasSignInController(connectionFactoryLocator, usersConnectionRepository,
                  new SimpleSignInAdapter(), env.getProperty("facebook.appKey"), env.getProperty("facebook.appSecret"),
                  env.getProperty("facebook.canvasPage"));
      }*/
  }
  </code></pre>
  
  <p>After login in Facebook then we try to fetch user profile like</p>
  
  <pre><code>WebRequest request
  RegistrationForm dto = new RegistrationForm();
  Connection&lt;?&gt; connection = ProviderSignInUtils.getConnection(request);
  
   if (connection != null) {
              UserProfile socialMediaProfile = connection.fetchUserProfile();
              System.out.println("DTO EMAIL---&gt;"+socialMediaProfile.getEmail());
              dto.setEmail(socialMediaProfile.getEmail());
              dto.setFirstName(socialMediaProfile.getFirstName());
              dto.setLastName(socialMediaProfile.getLastName());
    }
  </code></pre>
  
  <p>I try to get the email and username but is not working.And first name and last name properly fetched.</p>