简体   繁体   English

如何在spring boot中一起使用auth0和swagger?

[英]How do I use auth0 and swagger together in spring boot?

I am trying to use both Swagger and Auth0. 我试图使用Swagger和Auth0。 Swagger alone is working fine when I'm hitting http://localhost:8080/swagger-ui . 当我点击http:// localhost:8080 / swagger-ui时,Swagger工作正常。 But, after configuring auth0. 但是,在配置auth0之后。 It is showing 403 Forbidden Error 它显示403 Forbidden Error

I'm using spring boot with gradle. 我正在使用带有gradle的弹簧靴。 I've tried to antMatchers function to permit swagger and all. 我试过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/**");
    }
}

Since I'm learning and new to java and spring boot. 因为我正在学习java和spring boot的新手。 I expect http://localhost:8080/swagger-ui even without security is enough. 我希望http:// localhost:8080 / swagger-ui即使没有安全就足够了。

when do you encounter the 403 error? 你什么时候遇到403错误? Generally in a situation like this we would commend capturing a HAR file and then we would review the flow to see where the breakdown may have been. 通常在这种情况下,我们会建议捕获一个HAR文件,然后我们会检查流程以查看故障可能发生的位置。 However we need more information here to properly decide where the error is. 但是,我们需要更多信息来正确判断错误的位置。

That being said I have attached the Auth0 quickstart for spring that may help provide some insight. 话虽如此,我已经附上了春天的Auth0快速入门,可能有助于提供一些见解。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM