spring-boot - 使用 Spring Social Google 提供程序的 Spring Boot

标签 spring-boot spring-social spring-social-google

任何示例如何将 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/

相关文章:

java - 如何在 Spring Social 中获取早于特定 id 的推文

spring - 使用 facebook 登录并使用 oauth 2.0 对 REST api 调用进行身份验证

Spring Security 5 Google OAuth2 错误 - 需要重定向才能获得用户批准(UserRedirectRequiredException)

java - Spring Social Google - 将一次性授权代码转换为服务器上的访问 token /刷新 token

java - 服务器日志在哪里

java - 如何动态更新信任库?

java - 在 JPA sql 查询中,HIbernate 无法解析 foreignKey 列

java - 如果从计划作业调用,Spring Boot 存储库不会保存到数据库

c# - 在 LinkedIn 上获得公司关注者