Forum Discussion
- fehguyStaff
Hi, can you describe what you're trying to do a bit more? How are you logging into your app to get a cookie, and how is SwaggerHub supposed to pass it? If you can explain, we may be able to help.
- switzerOccasional Contributor
Here are some details:
We have a relatively simple Rails application that powers an analytics dashboard. In order to log into the application, a user goes through a login process, and a session cookie is set for this user.
When the user requests a dashboard screen, the API is called to get time series data about a given object. This session cookie is passed, and a JSON result is returned. Here is an example of a working script (with the session cookie values modified):
curl 'https://app.authenticated.digital/analytics/custom?fields=platform%2Cexchange%2Ctotal&sorts=-total&limit=50&page=1&granularity=all&start_date=2016-06-14&end_date=2016-06-15' -H 'Accept-Encoding: gzip, deflate, sdch, br' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36' -H 'Accept: application/json' -H 'Referer: https://app.authenticated.digital/analysis/all/authentic_dsp/' -H 'Cookie: remember_user_token=fjsdlkfjsdlkfjsdlkfjsldkfjsldkfj--dlsdjflsdifjlsdkfjdslkfjsdlf; _admin_session=flkjsdflksdjflksdjflksdjflksdjfldksfjsldkfj--dfkjsdlfkjdsflksdjflksdjfd' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed
When SwaggerHub uses XHR to pass in the request, the cookies are not passed, so I receive a 401 not authorized error.
I have read in the forums that there may be the ability to pass cookies (e.g. with-credentials: true) by passing in "enableCookies: true" in the Swagger definition file. This does not seem to work.
I'd like to be able to set a flag somewhere in the Swagger definition file to instruct XHR to pass cookies with the JSON request.
Thanks!
P.S. I know that using cookie based authentication is not the preferred method of auth, but one FANTASTIC application of Swagger is to document existing API that may have been written in this way - and I would imagine that a large percentage of API's implement authentication this way. Two popular examples are JIRA and Wordpress.
- fehguyStaff
OK I think I get it--but how are you entering your cookie values from the UI (assuming the interactive UI in swaggerhub)?
Related Content
- 2 years ago
- 8 years ago
Recent Discussions
- 3 days ago
- 2 months ago