Hello.
I have a problem. I setuped swagger like that.
Swagger spring configuration class
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket restfulApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("metadata-api")
.select()
.build()
.securitySchemes(Collections.singletonList(oauth()))
.securityContexts(Collections.singletonList(securityContext()))
.apiInfo(apiInfo());
}
@Bean
public SecurityContext securityContext() {
AuthorizationScope readScope = new AuthorizationScope("admin",
"Accès en tant
qu'administrateur");
AuthorizationScope[] scopes = new AuthorizationScope[1];
List<SecurityReference> securityReferences = new ArrayList<>();
scopes[0] = readScope;
securityReferences.add(
SecurityReference.builder()
.reference("metadata_oauth")
.scopes(scopes)
.build());
return SecurityContext.builder()
.securityReferences(securityReferences)
.forPaths(ant("/**"))
.build();
}
@Bean
public SecurityConfiguration securityInfo() {
return new SecurityConfiguration("clientId", "clientSecret",
"metadata", "matadata", "", ApiKeyVehicle.HEADER, "", " ");
}
@Bean
SecurityScheme oauth() {
return new OAuthBuilder()
.name("oauth2")
.grantTypes(grantTypes())
.scopes(scopes())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfo(
"Moteur Metadata",
"Description",
"7.0.0",
"",
new Contact("Enteprise", "", ""),
"",
"", Collections.emptyList());
}
private List<AuthorizationScope> scopes() {
List<AuthorizationScope> scopes = new ArrayList<>();
scopes.add(new AuthorizationScope("admin", "Accès en tant
qu'administrateur"));
return scopes;
}
private List<GrantType> grantTypes() {
List<GrantType> grantTypes = new ArrayList<>();
grantTypes.add(new ImplicitGrantBuilder()
.loginEndpoint("http://localhost/authorizaton/authorize"))
.build());
return grantTypes;
}
}
so, swagger-ui is correctly authenticated but when I run a query, the
header does not contain the oauth token.
Request Headers
{
"Accept": "*/*"
}
Response Body
<UnauthorizedException>
<error>unauthorized</error>
<error_description>An Authentication object was not found in the
SecurityContext</error_description>
</UnauthorizedException>
Do you have any idea?
Thierry
--
--
You received this message because you are subscribed to the Google Groups
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.