Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot with Spring Social Google provider

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?

like image 476
Zveratko Avatar asked Sep 02 '15 12:09

Zveratko


People also ask

How do I use Google authentication in spring boot?

Run the JAR file by using the command java –jar <JARFILE> and application is started on the Tomcat port 8080. Now hit the URL http://localhost:8080/ and click the Google Login link. It will redirect to the Google login screen and provide a Gmail login details.

Is OAuth2RestTemplate deprecated?

RELEASE classes such as OAuth2RestTemplate , OAuth2ProtectedResourceDetails and ClientCredentialsAccessTokenProvider have all been marked as deprecated.

What is OAuth 2.0 in spring boot?

OAuth2 is an authorization framework that enables the application Web Security to access the resources from the client. To build an OAuth2 application, we need to focus on the Grant Type (Authorization code), Client ID and Client secret.

What is oauth2login?

OAuth 2.0 Login leverages the Authorization Code Grant. Therefore, the authorization credential is the authorization code. The default Authorization Response baseUri (redirection endpoint) is /login/oauth2/code/* , which is defined in OAuth2LoginAuthenticationFilter.


1 Answers

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.

like image 173
de_xtr Avatar answered Oct 27 '22 22:10

de_xtr