Swagger UI - oAuth enabled rest app Issue

105 views
Skip to first unread message

Karuppan Pl

unread,
Jun 24, 2017, 2:39:39 AM6/24/17
to Swagger
Hi experts,
am facing an issue in my application. i have enabled oauth for my spring boot project ( rest service). i have created a rest client to access the oauth enabled api. 
when i load my swaggerui ( 2.5 version) 
{
  "error": "unauthorized",
  "error_description": "Full authentication is required to access this resource"
}

if i hit the end point via post man it works. because post man is a nice tool where i can enter bearer token and invoke the service. 

in swagger configuration java file we should have an option. 

 @Override
    public void configure(HttpSecurity http) throws Exception
    {
        http.csrf().disable().antMatcher("/**") // this will apply to the entire
                                                // web server
                .authorizeRequests()
                .antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security",
                        "/swagger-ui.html", "/webjars/**", "/swagger-resources/configuration/ui", "/swagger-ui.html",
                        "/swagger-resources/configuration/security")
                .permitAll() 
                .antMatchers("/**").access("#oauth2.hasScope('ownresource.read')"); <!-- tried this -->
.anyRequest().hasAuthority("ownresource.read"); <!-- tried this one too with out the above line -->
    }

Please guide me with the right configuration which will enable me to access the application through swagger UI as well. we test our application via swagger most of the times. 

if there is a way to externalize the client id , client secret , token url and use it the above configuration, it will be really great. kind of little urgent. any help us much appreciated.
Reply all
Reply to author
Forward
0 new messages