簡體   English   中英

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

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

我試圖使用Swagger和Auth0。 當我點擊http:// localhost:8080 / swagger-ui時,Swagger工作正常。 但是,在配置auth0之后。 它顯示403 Forbidden Error

我正在使用帶有gradle的彈簧靴。 我試過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即使沒有安全就足夠了。

你什么時候遇到403錯誤? 通常在這種情況下,我們會建議捕獲一個HAR文件,然后我們會檢查流程以查看故障可能發生的位置。 但是,我們需要更多信息來正確判斷錯誤的位置。

話雖如此,我已經附上了春天的Auth0快速入門,可能有助於提供一些見解。

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