【问题标题】:How do I use auth0 and swagger together in spring boot?如何在 Spring Boot 中同时使用 auth0 和 swagger?
【发布时间】:2019-11-02 12:19:32
【问题描述】:

我正在尝试同时使用 Swagger 和 Auth0。当我点击http://localhost:8080/swagger-ui 时,仅 Swagger 就可以正常工作。但是,在配置 auth0.它显示403 Forbidden Error

我正在使用带有 gradle 的 spring boot。我已经尝试使用 antMatchers 函数来允许招摇和所有。

public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Value(value = "${auth0.apiAudience}")
    private String apiAudience;
    @Value(value = "${auth0.issuer}")
    private String issuer;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        JwtWebSecurityConfigurer
                .forRS256(apiAudience, issuer)
                .configure(http)
                .cors().and().csrf().disable().authorizeRequests()
                .antMatchers("/v2/api-docs", "/swagger-resources/configuration/ui", "/swagger-resources", "/swagger-resources/configuration/security", "/swagger-ui.html", "/webjars/**").permitAll()
                .and()
                .authorizeRequests()    
                .anyRequest()
                .authenticated()
                .and()
                .csrf().disable();
    }
    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/v2/api-docs", "/swagger-resources/configuration/ui", "/swagger-resources", "/swagger-resources/configuration/security", "/swagger-ui.html", "/webjars/**");
    }
}

因为我正在学习并且对 java 和 spring boot 很陌生。我希望http://localhost:8080/swagger-ui 即使没有安全措施也足够了。

【问题讨论】:

    标签: java spring-boot gradle swagger-ui auth0


    【解决方案1】:

    什么时候遇到 403 错误?一般来说,在这种情况下,我们会推荐捕获 HAR 文件,然后我们会查看流程以查看可能出现故障的位置。但是,我们需要更多信息来正确确定错误在哪里。

    话虽如此,我已经附上了春季的 Auth0 快速入门,这可能有助于提供一些见解。

    https://auth0.com/docs/quickstart/backend/java-spring-security/01-authorization

    【讨论】:

      猜你喜欢
      • 2017-06-29
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 2023-02-08
      • 2016-07-21
      • 2022-01-25
      相关资源
      最近更新 更多