任何示例如何将 Spring Boot 应用程序与 Spring Social Google ( GabiAxel/spring-social-google ) 提供程序集成?我找到了这个 project ,但似乎还没有完成。 Spring Boot 解释了如何让它与 Spring Facebook、Twitter 一起使用,但是使用 Google 登录是否相同?
最佳答案
正如您在问题中提到的,您可以使用托管在 github 上的项目。
你可以用这个dependency
在 Configuration 类中,您必须扩展 SocialConfigurerAdapter,覆盖 addConnectionFactories 方法并添加 GoogleConnectionFactory。例如 :
@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;
}
}
您可以将其与 Spring Social 示例一起使用。
关于spring-boot - 使用 Spring Social Google 提供程序的 Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32353349/