Header are not added from java script with swaggerUi.api.clientAuthorizations.add(), but exist in Cu

48 views
Skip to first unread message

Hitendrasinh Mahida

unread,
Jul 6, 2016, 12:57:38 PM7/6/16
to Swagger
  • swagger-ui version 2.0
  • a swagger file reproducing the issue : index.html

I am trying to add header named 'token' for each api call as;


swaggerUi.api.clientAuthorizations.add("key1", new SwaggerClient.ApiKeyAuthorization("token", "bearerToken", "header"));


But I do not receive that header on server, also inspecting request header in browser is not showing that newly added header, it just send standard default headers.


But, swagger info message for the curl request for the same shows the header I added.


What could be the reason?

tony tam

unread,
Jul 7, 2016, 1:25:13 PM7/7/16
to swagger-sw...@googlegroups.com
Hmm. Well, the header is only added if it meets the security requirements, meaning there are no security elements defined, or they don’t match.  Please share your JSON or YAML definition and we can look into it.

--
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 swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hitendrasinh Mahida

unread,
Jul 19, 2016, 9:26:23 AM7/19/16
to Swagger

Hi,
Here is part of yaml file;


securityDefinitions:
  key:
    type: "apiKey"
    in: "header"
    name: "token"
  
host: "10.x.1.x"

basePath: "/a/bs/api/v1"
schemes:
- "https"
produces:
- "application/json"

paths:
  /GetConfig:
    get:
      tags:
      - "Devices"
      security:
        - key: []
      summary: "Get Device Config"
      description: "Information about the current configurations for device."
     
      parameters:
.
.
.

And I use ;

swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("token", bearerToken, "header"));

my request Header sent is as;

  1. OPTIONS /a/bs/api/v1/GetConfig?Id=6 HTTP/1.1 Host: :84.410.240.1 Connection: keep-alive Access-Control-Request-Method: GET Origin: http://localhost:8080 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 Access-Control-Request-Headers: accept, token Accept: */* Referer: http://localhost:8080/ Accept-Encoding: gzip, deflate, sdch, br Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Thanks!

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Hitendrasinh Mahida

unread,
Jul 19, 2016, 9:30:09 AM7/19/16
to Swagger
Also the Curl is created correct as below;

CURL created as;

curl -X GET --header 'Accept: application/json' --header 'token: ffsdfsdffsfdffsdfsdfsdf' 'https://10.x.1.x/iot/bs/api/v1/GetConfig?sensorId=6'

;/
Reply all
Reply to author
Forward
0 new messages