Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to get api-key security schema working #2809

Unanswered
ahoehma asked this question in Q&A
Discussion options

May a stupid question but I can't find a docu or howto or something.

I have already this:

@Configuration
class OpenApiConfiguration {
 @Bean
 OpenAPI customOpenAPI(final CadWebServiceProperties properties) {
 return new OpenAPI()
 .components(
 new Components()
 .addSecuritySchemes("apiKey",
 new SecurityScheme().type(APIKEY).in(In.HEADER).name(properties.authTokenHeaderName())));
 }
}

I can use the schema in swagger ui:

image

But then when I send requests ... the header is not in requests. I checked with chrome network console.

Where is the missing magic?

Kind regards
Andreas

You must be logged in to vote

Replies: 2 comments

Comment options

We used something like this and it works:

`@Configuration
public class SwaggerConfiguration {

public static final String SEC_SCHEME_NAME = "Access Token";
@Bean
public OpenAPI openAPI() {
 return new OpenAPI()
 .components(new Components().addSecuritySchemes(SEC_SCHEME_NAME, securityScheme()))
 .addSecurityItem(new SecurityRequirement().addList(SEC_SCHEME_NAME));
}
private SecurityScheme securityScheme() {
 return new SecurityScheme()
 .type(SecurityScheme.Type.APIKEY)
 .in(SecurityScheme.In.HEADER)
 .name(AUTHORIZATION);
}

}`

You must be logged in to vote
0 replies
Comment options

I will re-test this asap.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /