Quantcast
Channel: Spring Community Forums - Social
Viewing all articles
Browse latest Browse all 145

Authorize with only one specified Facebook App

$
0
0
I would like to get my facebook page videos. I need to authorize for that. However, for Photos you don't need to authorize.

So I created a Facebook App. But how I need to configure (JavaConfig) Spring now to use that App to authorize?

Do I really need to store the token in my database? And what to write to replace SecurityContext.getCurrentUser()?

Code:

@Configuration
public class SocialConfig {
    private @Autowired Environment env;
    private @Autowired DataSource dataSource;

    public @Bean ConnectionFactoryLocator connectionFactoryLocator() {
        ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
        registry.addConnectionFactory(new FacebookConnectionFactory(env.getProperty("facebook.clientId"),
                env.getProperty("facebook.clientSecret")));
        return registry;
    }

    public @Bean UsersConnectionRepository usersConnectionRepository() {
        JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource,
                connectionFactoryLocator(), Encryptors.noOpText());
        repository.setConnectionSignUp(new SimpleConnectionSignUp());
        return repository;
    }

    @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
    public @Bean ConnectionRepository connectionRepository() {
        User user = SecurityContext.getCurrentUser();
        return usersConnectionRepository().createConnectionRepository(user.getId());
    }

    @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
    public @Bean Facebook facebook() {
        return connectionRepository().getPrimaryConnection(Facebook.class).getApi();
    }
}


Viewing all articles
Browse latest Browse all 145

Trending Articles