Spring Boot with Spring Social Google provider

2k Views Asked by At

Any example how to integrate Spring Boot application with Spring Social Google (GabiAxel/spring-social-google) provider? I found this project, but it seems to be unfinished. Spring Boot explains how to get it working with Spring Facebook, Twitter, but is it the same for log in with Google?

1

There are 1 best solutions below

1
On

As you have mentioned in your question, you can use that project hosted on github.

You can use this dependency

In a Configuration class, you will have to extend SocialConfigurerAdapter, override the addConnectionFactories method and add GoogleConnectionFactory. For example :

@Configuration
@EnableSocial
public class SocialConfig extends SocialConfigurerAdapter {
@Override
public void addConnectionFactories(ConnectionFactoryConfigurer connectionFactoryConfigurer, Environment environment) {
    GoogleConnectionFactory googleConnectionFactory = new GoogleConnectionFactory(environment.getProperty("spring.social.google.app-id"), environment.getProperty("spring.social.google.app-secret"));
    googleConnectionFactory.setScope("https://www.googleapis.com/auth/plus.login");
    connectionFactoryConfigurer.addConnectionFactory(googleConnectionFactory);
}
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Google google(ConnectionRepository repository) {
    Connection<Google> connection = repository.findPrimaryConnection(Google.class);
    return connection != null ? connection.getApi() : null;
}
}

You can use this along with the Spring Social examples.