{"action":"created","issue":{"url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/818","labels_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/818/labels{/name}","comments_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/818/comments","events_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/818/events","html_url":"https://github.com/swagger-api/swagger-ui/issues/818","id":53842538,"number":818,"title":"How to integrate with jwt based authentication?","user":{"login":"bebraw","id":166921,"avatar_url":"https://avatars.githubusercontent.com/u/166921?v=3","gravatar_id":"","url":"https://api.github.com/users/bebraw","html_url":"https://github.com/bebraw","followers_url":"https://api.github.com/users/bebraw/followers","following_url":"https://api.github.com/users/bebraw/following{/other_user}","gists_url":"https://api.github.com/users/bebraw/gists{/gist_id}","starred_url":"https://api.github.com/users/bebraw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bebraw/subscriptions","organizations_url":"https://api.github.com/users/bebraw/orgs","repos_url":"https://api.github.com/users/bebraw/repos","events_url":"https://api.github.com/users/bebraw/events{/privacy}","received_events_url":"https://api.github.com/users/bebraw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/swagger-api/swagger-ui/labels/Feature","name":"Feature","color":"009800"},{"url":"https://api.github.com/repos/swagger-api/swagger-ui/labels/P2","name":"P2","color":"0052cc"},{"url":"https://api.github.com/repos/swagger-api/swagger-ui/labels/Security","name":"Security","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/swagger-api/swagger-ui/milestones/8","html_url":"https://github.com/swagger-api/swagger-ui/milestones/v2.1.1","labels_url":"https://api.github.com/repos/swagger-api/swagger-ui/milestones/8/labels","id":1155156,"number":8,"title":"v2.1.1","description":"","creator":{"login":"webron","id":241629,"avatar_url":"https://avatars.githubusercontent.com/u/241629?v=3","gravatar_id":"","url":"https://api.github.com/users/webron","html_url":"https://github.com/webron","followers_url":"https://api.github.com/users/webron/followers","following_url":"https://api.github.com/users/webron/following{/other_user}","gists_url":"https://api.github.com/users/webron/gists{/gist_id}","starred_url":"https://api.github.com/users/webron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webron/subscriptions","organizations_url":"https://api.github.com/users/webron/orgs","repos_url":"https://api.github.com/users/webron/repos","events_url":"https://api.github.com/users/webron/events{/privacy}","received_events_url":"https://api.github.com/users/webron/received_events","type":"User","site_admin":false},"open_issues":39,"closed_issues":0,"state":"open","created_at":"2015-06-08T15:40:01Z","updated_at":"2015-06-15T17:17:01Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2015-01-09T07:54:52Z","updated_at":"2015-06-18T15:00:30Z","closed_at":null,"body":"I set up [a little example](https://github.com/bebraw/swagger-todo) that shows how to build a minimal Todo backend using Express, jwt and co. The problem is that `swagger-ui` relies on api key. I noticed it's possible to customize this a little bit (ie. push api key to header) but that doesn't solve the problem entirely.\r\n\r\nI would need some way to log in to the system first. I will be able to get the token required by authentication through that.\r\n\r\nAn extra challenge is how to make this all work nicely with [swagger-tools](https://github.com/apigee-127/swagger-tools) but that's a separate problem. If there was a nice extension point for something like this, it would probably be easier to handle that side. I would just need something that can be plugged into an Express middleware and served as a static site through it."},"comment":{"url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/comments/113185459","html_url":"https://github.com/swagger-api/swagger-ui/issues/818#issuecomment-113185459","issue_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/818","id":113185459,"user":{"login":"Qwerios","id":254447,"avatar_url":"https://avatars.githubusercontent.com/u/254447?v=3","gravatar_id":"","url":"https://api.github.com/users/Qwerios","html_url":"https://github.com/Qwerios","followers_url":"https://api.github.com/users/Qwerios/followers","following_url":"https://api.github.com/users/Qwerios/following{/other_user}","gists_url":"https://api.github.com/users/Qwerios/gists{/gist_id}","starred_url":"https://api.github.com/users/Qwerios/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Qwerios/subscriptions","organizations_url":"https://api.github.com/users/Qwerios/orgs","repos_url":"https://api.github.com/users/Qwerios/repos","events_url":"https://api.github.com/users/Qwerios/events{/privacy}","received_events_url":"https://api.github.com/users/Qwerios/received_events","type":"User","site_admin":false},"created_at":"2015-06-18T15:00:30Z","updated_at":"2015-06-18T15:00:30Z","body":"I hacked this into index.html today to get it working. I changed the addApiKeyAuthorization implementation to the following:\r\n\r\n```\r\n      function addApiKeyAuthorization(){\r\n        var key = encodeURIComponent( $('#input_apiKey')[0].value );\r\n        if(key && key.trim() != \"\") {\r\n            var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization( \"Authorization\", \"Bearer \" + key, \"header\" );\r\n            window.swaggerUi.api.clientAuthorizations.add( \"bearer\", apiKeyAuth );\r\n            log( \"Set bearer token: \" + key );\r\n        }\r\n      }\r\n```\r\n\r\nThe security definition in my swagger.json looks like this:\r\n```\r\n  \"securityDefinitions\": {\r\n    \"bearer\": {\r\n      \"type\": \"apiKey\",\r\n      \"name\": \"Authorization\",\r\n      \"in\": \"header\"\r\n    }\r\n  }\r\n```\r\n\r\nToken is now being set in the headers for each request where I indicate the \"bearer\" security is required. I'll likely tack on a little localStorage magic to store the token in the browser to persist beyond reloads.\r\n\r\nHope this helps someone"}}