Spring引导2.0.0.M7和Oauth2不会触发初始重定向

问题描述 投票:0回答:1

我正在使用Spring boot 2.0.0.M7,我无法让OAuth2工作。我有它在Facebook和github在M4下工作。 (它在M5中改变了,我没有尝试升级它)。

我似乎无法触发从我的应用程序到oauth提供程序的初始重定向。使用提供商1(facebook),以前/ login / facebook过滤器将重定向到外部OAuth2。现在......我不知道我需要点击以触发令牌/重定向逻辑的URL(可能在文档中丢失?)。

https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-security-oauth2提及/ login / oauth2 / code / * - 但这似乎是针对提供者的响应,并不会触发重定向。

我当前的配置如下(并且在M4中工作的挂钩已作为注释保留)

@Configuration
@EnableWebSecurity
@EnableOAuth2Client
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// ...
@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
        .exceptionHandling()
            .authenticationEntryPoint(new AuthenticationEntryPoint() {
                @Override
                public void commence(HttpServletRequest request, HttpServletResponse response,
                        AuthenticationException authException) throws IOException, ServletException {
                    response.sendRedirect("/login");
                }
            })
            .and()
        .authorizeRequests()
            .antMatchers("/", "/favicon.ico", "/static/**", "/login", "/login/**", "/logout", "/at/**").permitAll()
            .anyRequest().authenticated()
        .and()
//      .addFilterBefore(new OAuth2ClientContextFilter(), BasicAuthenticationFilter.class)
//      .addFilterBefore(oauthFilter("facebook"), BasicAuthenticationFilter.class)
//      .addFilterBefore(githubFilter(), BasicAuthenticationFilter.class)
        .csrf()
            .disable()
        .rememberMe()
            .alwaysRemember(true)
        ;

        http.httpBasic().disable();
        http.formLogin().disable();
    }
// private Filter facebookFilter() {
//  @Bean @ConfigurationProperties("facebook.client") public AuthorizationCodeResourceDetails facebook() {
// ...
}

登录页面包含指向/ login / facebook和/ login / github的链接。

我的application.yml是:

spring.security.oauth2.client.registration:
  # developer.facebook.com
  facebook:
    client-id: redacted
    client-secret: redacted
  #https://github.com/settings/applications/redacted
  github:
    client-id: redacted
    client-secret: redacted

并且因为它可能有所帮助,所以从build.gradle中选择一些依赖项:

compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.security.oauth:spring-security-oauth2:2.2.1.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework:spring-context:5.0.2.RELEASE'
compile 'org.springframework.security:spring-security-web:5.0.0.RELEASE'
compile 'org.springframework.security:spring-security-oauth2-client:5.0.0.RELEASE'

我已经花了很多年的时间与圈子一起。任何帮助欢迎:)谢谢

spring-mvc spring-boot oauth-2.0 spring-security-oauth2
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.