如何使用Google OAuth2注销?

时间:2020-07-30 06:06:43

标签: spring-boot oauth-2.0 spring-security-oauth2

我正在尝试注销,并且正在使用Spring Boot 2.1.7.RELEASE和Google OAuth2。 这是我的课程,实现了WebSecurityConfigurerAdapter

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .headers().frameOptions().disable()
                .and()
                    .authorizeRequests()
                    .antMatchers("/", "/css/**", "/images/**", "/js/**", "/h2-console/**").permitAll()
                    .antMatchers("/**").hasRole(Role.USER.name())
                    .anyRequest().authenticated()
                .and()
                    .logout().logoutUrl("/logout").invalidateHttpSession(true)
                        .clearAuthentication(true)
                        .logoutSuccessUrl("/").deleteCookies("JSESSIONID").permitAll()
                    .and().csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .and()
                    .oauth2Login()
                        .userInfoEndpoint()
                            .userService(customOAuth2UserService);
    }

这是我的@Controller代码,用于Http-GET请求“ / logout”。

@GetMapping("/logout")
    public String logout(HttpServletRequest request, HttpServletResponse response) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if(authentication != null) {
            new SecurityContextLogoutHandler().logout(request, response, authentication);
        }
        SecurityContextHolder.getContext().setAuthentication(null);
        return "index";
    }

我几乎尝试了所有我搜索过的并在Stackoverflow上看到的内容,但每次似乎都无法完全注销。

0 个答案:

没有答案
相关问题