Oauth2 访问oauth/authorize/**出现 403

Posted _DiMinisH

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oauth2 访问oauth/authorize/**出现 403相关的知识,希望对你有一定的参考价值。

问题: Oauth2 访问oauth/authorize/**出现 403


访问的url

http://localhost:8080/oauth/authorize?response_type=code&client_id=client&redirect_uri=http://www.baidu.com&scope=all

解决方案

修改继承WebSecurityConfigurerAdapter类中的protected void configure(HttpSecurity http)方法

旧的

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter 

    @Bean
    public PasswordEncoder passwordEncoder () 
        return new BCryptPasswordEncoder();
    

    @Override
    protected void configure(HttpSecurity http) throws Exception 
        http.authorizeRequests(request ->
                request.antMatchers("/oauth/**", "/login/**", "/logout/**")
                        .permitAll()
                        .anyRequest().authenticated()
        ).csrf(AbstractHttpConfigurer::disable);

    

新的

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter 

    @Bean
    public PasswordEncoder passwordEncoder () 
        return new BCryptPasswordEncoder();
    

    @Override
    protected void configure(HttpSecurity http) throws Exception 
        http.formLogin().and().authorizeRequests(request ->
                request.antMatchers("/oauth/**", "/login/**", "/logout/**")
                        .permitAll()
                        .anyRequest().authenticated()
        ).csrf(AbstractHttpConfigurer::disable);

    

以上是关于Oauth2 访问oauth/authorize/**出现 403的主要内容,如果未能解决你的问题,请参考以下文章