0

I have Spring Boot application. And I want to integrate swagger in my project.

I am using springfox 2.7.0 and auth0 for authentication on swagger, but I have problem with send id_token from auth0 to header of swagger.

This is my code for Swagger configuration:

@Bean
public Docket api() { 

return new Docket(DocumentationType.SWAGGER_2)  
  .select()              
  .apis(RequestHandlerSelectors.basePackage("name.web"))              
  .paths(PathSelectors.any())                          
  .build()
  .apiInfo(apiInfo())
  .securitySchemes(Collections.singletonList(securitySchema()));            

}

 private OAuth securitySchema() {

   List<AuthorizationScope> authorizationScopeList = new ArrayList<>();

   authorizationScopeList.add(new AuthorizationScope("openid", "access all"));

    List<GrantType> grantTypes = new ArrayList<>();

    final TokenRequestEndpoint tokenRequestEndpoint = new TokenRequestEndpoint("https://bovinet.auth0.com/authorize", "clientId", "secretKey");

    final TokenEndpoint tokenEndpoint = new TokenEndpoint("http://server.com/oauth/token", "id_token");


    AuthorizationCodeGrant authorizationCodeGrant = new 
    AuthorizationCodeGrant(tokenRequestEndpoint, tokenEndpoint);

    grantTypes.add(authorizationCodeGrant);

    OAuth oAuth = new OAuth("oauth2", authorizationScopeList, grantTypes);

    return oAuth;
 }


 private ApiInfo apiInfo() {
    @SuppressWarnings("deprecation")
     ApiInfo apiInfo = new ApiInfo(
    "Name", "", "", "", "", "", "");
     return apiInfo;
 }

 @Bean
 SecurityConfiguration security() {
  return new SecurityConfiguration(
   "clientId",
   "secretKey",
   "test-app-realm",
   "https://server.com",
   "api_key",
   ApiKeyVehicle.HEADER, 
   "Authorization", 
   "," /*scope separator*/);
}

When I open console for swagger-ui.htm page I can see id_token in response of /oauth/token request but I don't know how put that token in header of swagger.

Can somebody please help me to resolve this problem?

dzivi
  • 33
  • 1
  • 11
  • Do you have a git repo you can share? – arcseldon Sep 28 '17 at 23:33
  • Also, only commenting - not sure I fully understood your specific requirements - but something sounded odd about you using the Id Token in the swagger header. Can you clarify your architecture - are you receiving a successful authentication from Auth0 in some app, and then trying to call an API passing the id token currently? Am only slightly familiar with SpringFox hence the ask. – arcseldon Sep 28 '17 at 23:39

0 Answers0