【问题标题】:spring boot and google oauth春季启动和谷歌oauth
【发布时间】:2015-01-29 19:25:32
【问题描述】:

我查看了 Google 文档上的 Oauth2 工作流程,它看起来非常直观。使用基本的 servlet,我了解如何处理所有回调,但是使用 Spring Boot,如果我使用 oauth 和 Spring 安全模块,我对我需要做什么感到有点困惑。

我找到了一个教程here,描述了如何使用用户名和密码添加身份验证,但我不确定这是否是我需要的最佳选择,因为我主要想限制页面中的内容而不是页面本身。无论如何,假设我需要每页进行身份验证,我该如何设置使用 Oauth 的用户?查看教程,似乎安全模块正在做一些魔术来检查内存数据库中的用户名/密码。

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/", "/home").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }
}

在上面的示例中,我看到configureGlobal 设置了要检查的用户名/密码存储。 spring boot 是否有用户名/密码的硬编码逻辑,会阻止我将它用于 Oauth2?我应该忽略这个安全模块并使用我自己的处理程序直接设置用户吗?

【问题讨论】:

  • 最后你是如何配置你的项目使用 oauth 和 google 的?

标签: google-oauth spring-boot


【解决方案1】:

如果您只需要知道 Google 认为您的用户是谁,那么您很乐意自己处理所有您不一定需要 Spring Security 的事情。还有一个 Spring Social Google 库 here,您可以使用它来实现回调。

【讨论】:

    猜你喜欢
    • 2022-10-19
    • 2016-01-28
    • 1970-01-01
    • 2017-10-06
    • 2014-08-05
    • 1970-01-01
    • 2019-06-01
    • 1970-01-01
    • 2017-09-11
    相关资源
    最近更新 更多