-
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
Swagger-UI refuses to add request header #1244
Comments
That's probably because of a known bug. Can you try the develop_2.0 branch? |
Just tried it and the same thing happened.
I've also tried changing apiKeyAuth to 'header' instead of query, no dice |
Yes, a legacy line has been causing some hair-loss. |
That fixed the initial crash I was having, but unfortunately still didn't add a header. I'm inspecting the request both on the chrome side and grape side and there's nothing in either |
Ok, I'm going to replicate. You're using the readme example, from develop_2.0? |
The key in the example is a "query" key, meaning it gets attached to var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
// to this...
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "header"); // <- make it a header key |
We currently support "query" and "header" auth keys, although there is a mechanism to manipulate each request before it gets executed, meaning you can have access to all headers, parameters, etc. Which is a little more "hands on" though. |
Not sure what I'm doing wrong, but I still can't see it. I downloaded the develop_2.0 branch and opened ./dist/index.html in chrome. I haven't changed anything but this line in the whole project. This is the entire contents of the script tag -
and this is what I see in Chrome's tab when I click explore -
|
Are you trying to use an api_key to access your spec? |
I was...I just whitelisted the swagger url and everything loaded...doh
|
Sorry, I'm back (so is github) Could be an error in the spec, that's causing this ugly error. Which isn't very friendly at all. |
Otherwise, you can share your definition with us and we'll try to find the problem. |
Anything new concerning the missing headers? |
think this is related? domaindrivendev/Swashbuckle.WebApi#353 I'm changing my request type from json to xml and it's not returning an error and just kicking back those javascript errors in the chrome console. don't mean to hijack but seems related so maybe this will help. |
@mrtristan - completely unrelated. |
hey @ifig, I don't think there is an actual issue with missing headers... but if you'd like to, you can show us your spec and we can see if anything sticks out. |
Well, I thought it was the same problem as described before : I want to request the url where my swagger specs are defined, but for that, I need to add a token in the header when I change the api key.
|
@ifig if you're hiding the spec itself behind an auth layer, take a look at this comment... |
Well, I have no idea of what happened, but I forked again the UI from github and now I can see the headers passing through... That's really weird though. Another question but I shouldn't probably ask it in this thread : is there a way to pass a token in the headers just to access the documentation (that's what I do for now), and then pass a different token in the headers for each route I test? |
Yup, I believe that's possible. It's not an area I'm familiar with... here is the spec reference .. https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#security-requirement-object and you can put it on the operation level... |
For future reference here is the Gist link I shared over IRC @ifig.... Allowing a custom callback function to alter the request object, pre-flight. |
@ponelat my issue was twofold -
Whenever grape swagger gets updated to swagger2.0 I'll switch to the current version of swagger UI |
@jaman1020 - have we covered the topic? |
Yeah, from my standpoint I'm good now, although I'm not sure if this issue has evolved into a separate concern other people have? |
What concern? Sorry, long thread. |
I hadn't looked too closely at it, but what @ifig and @mrtristan were referring to about their header troubles. Seemed to be slightly different than mine. |
Well, I'll leave it to @ponelat - though technically, worst case, they can open separate issues if it's unrelated. |
I believe the original issue (and some incidental) have been resolved? Closeable? |
Well, I'll close it due to lack of response from the other participants. Please open a new issue if needed. |
Hi, I'm having a similar problem I think that I've set up my swagger ui but when I check the headers they don't get sent. I have logs that tell me that the authentication keys get read in but never get sent in these request headers. Here's the relevant code
Thanks!! |
Hi! Same with @samillm problem. My js code is from repo. |
I'd suggest opening a new issue. This one is old and there have been several versions released since. |
This doesn't seem to work with the "Try it now" button in the GUI. Maybe this is going on? swagger-api/swagger-ui#1244
Hello all, I am trying to add 'Access-Control-Allow-Origin' in header. to do so i added this line... but i m getting this when i explore the request header :::>
there is no extra custom header added in the request header. it is adding my access-control-allow-origin as a value into Access-Control-Request-Headers. i want to add this access-control-allow-origin as a new custom header like .:::>
can any one suggest me, what am i doing wrong, or what should i do extra to do this ..... |
@nityanarayan44 if you have a new issue, it's better to open a new ticket. We can't track closed tickets. |
For those who land here, like me, looking for more information, the missing piece for me was the matching "securityDefinitions": {
"my_token": {
"type": "apiKey",
"description": "Authorization Token",
"name": "my_token",
"in": "header"
}
},
"security": [
{ "my_token": [] }
], Given that API spec, the JS code to match must use the same name, i.e. "my_token", as in: var tokenAuth = new SwaggerClient.ApiKeyAuthorization("Authorization", "Token " + token, "header");
window.swaggerUi.api.clientAuthorizations.add("my_token", tokenAuth); The |
@darrenleeweber thank you for sharing your findings, which are indeed correct based on the specification. |
@darrenleeweber a thumb up is not merely enough credit! THANK YOU!!!! ❤️ 😄 |
@darrenleeweber thanks! |
@darrenleeweber Thanks for this finding! Indeed solved my problem 👍 |
I work on Laravel 5.4, so i just edit file index.blade.php like below it works. i use Authentication header with Bearer function addApiKeyAuthorization() {
|
I've been pulling my hair out on this, not sure if I'm doing something wrong?
I have been unable to get a swagger-ui request to include ANY type of header. My Grape API uses an API token in the header for auth, and no matter what I do I cannot get it to show up in anything. I've tried all of the api-key example code, so I must be doing SOMETHING wrong.
However, upon closer inspection, even the demo petstore app does not contain an api header in the request headers.
I'm using the readme/sample code verbatim right now -
How can I get a request header of "api_key: value" to show up in request headers?
The text was updated successfully, but these errors were encountered: