-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authorization Header not getting displayed in CURL #5715
Comments
The specification does not allow explicitly adding Authorization header. For more information, please read https://swagger.io/docs/specification/describing-parameters/#header-parameters. |
The components:
securitySchemes:
auth:
type: apiKey
in: header
name: Authorization
security:
- auth: [] |
Thanks for your reply @hkosova , but the above approach didn't work for me. Find the screenshot for more details. and let me know what I am missing in it. |
@shivaprasad573 you need to remove the |
Thanks, @hkosova and it worked:), but in my use-case should remove that |
Could you please clarify what you mean by "pass ... value from YAML code only"? |
Sure @hkosova , in my use-case, My application will generate one |
A sample code that works. @Configuration
public class OpenApiConfig {
private static final String API_KEY = "apiKey";
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.components(new Components()
.addSecuritySchemes(API_KEY,apiKeySecuritySchema())) // define the apiKey SecuritySchema
.info(new Info().title("Title API").description(
"RESTful services documentation with OpenAPI 3."))
.security(Collections.singletonList(new SecurityRequirement().addList(API_KEY))); // then apply it. If you don't apply it will not be added to the header in cURL
}
public SecurityScheme apiKeySecuritySchema() {
return new SecurityScheme()
.name(Constants.AUTHORISATION_TOKEN) // authorisation-token
.description("Description about the TOKEN")
.in(SecurityScheme.In.HEADER)
.type(SecurityScheme.Type.APIKEY);
}
} |
Thought, it may help someone who are facing same problem.
|
Thanks @Sathyananth . It worked 👍🏼 |
Thanks a lot @Sathyananth |
I saw this issue is still open, I ran into the same problem recently because of tech debt, routes use several auth strategies and global auth is so inconvenient. I added a plugin to the swagger-ui and solved this problem. (tested on swagger 3.x, 4.x) export default function() {
let authorization;
return {
statePlugins: {
spec: {
wrapActions: {
executeRequest: (ori) => (req) => {
const { parameters } = req;
const auth = parameters['header.Authorization'] || parameters['header.authorization'];
authorization = auth;
return ori(req);
},
setMutatedRequest: (ori) => (path, method, req) => {
if (authorization) {
/**
* Because of `let parsedMutatedRequest = Object.assign({}, mutatedRequest)` in source,
* Change parsedMutatedRequest nested value affects mutatedRequest because of shallow copy.
* Another way is to use `requestInterceptor`
*/
req.headers.Authorization = authorization;
authorization = undefined;
}
return ori(path, method, req);
}
}
}
}
};
} SwaggerUI({
...
plugins: [
...
the_plugin
],
...
}); You should be aware what your are doing to use this method because this is against the standard. By the way, this hides the global auth. The |
I am trying to use the Authorization header in the swagger latest version.
You can try the above YAML configuration in Swagger Editor.
You can observe that the Authorization header which I added in the header section is not included in the CURL command.
openapi.txt
Help me to add an Authorization header into my API.
The text was updated successfully, but these errors were encountered: