{"action":"created","issue":{"url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/2234","repository_url":"https://api.github.com/repos/swagger-api/swagger-ui","labels_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/2234/labels{/name}","comments_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/2234/comments","events_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/2234/events","html_url":"https://github.com/swagger-api/swagger-ui/pull/2234","id":161912194,"number":2234,"title":"Add support for JWT token based authentication","user":{"login":"K1ll3rF0x","id":988779,"avatar_url":"https://avatars0.githubusercontent.com/u/988779?v=3","gravatar_id":"","url":"https://api.github.com/users/K1ll3rF0x","html_url":"https://github.com/K1ll3rF0x","followers_url":"https://api.github.com/users/K1ll3rF0x/followers","following_url":"https://api.github.com/users/K1ll3rF0x/following{/other_user}","gists_url":"https://api.github.com/users/K1ll3rF0x/gists{/gist_id}","starred_url":"https://api.github.com/users/K1ll3rF0x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/K1ll3rF0x/subscriptions","organizations_url":"https://api.github.com/users/K1ll3rF0x/orgs","repos_url":"https://api.github.com/users/K1ll3rF0x/repos","events_url":"https://api.github.com/users/K1ll3rF0x/events{/privacy}","received_events_url":"https://api.github.com/users/K1ll3rF0x/received_events","type":"User","site_admin":false},"labels":[{"id":429757691,"url":"https://api.github.com/repos/swagger-api/swagger-ui/labels/No%20fix%20needed","name":"No fix needed","color":"f9d0c4","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":23,"created_at":"2016-06-23T12:37:19Z","updated_at":"2017-05-08T09:43:05Z","closed_at":"2016-06-23T14:39:59Z","pull_request":{"url":"https://api.github.com/repos/swagger-api/swagger-ui/pulls/2234","html_url":"https://github.com/swagger-api/swagger-ui/pull/2234","diff_url":"https://github.com/swagger-api/swagger-ui/pull/2234.diff","patch_url":"https://github.com/swagger-api/swagger-ui/pull/2234.patch"},"body":"This pull request adds support for JWT token based authentication in Swagger UI. \n\nThe motivation of adding this feature is that many organizations (including my organization) secure their apis with JWT based authentication. Earlier approaches in implementing this feature have been hacky at best, or they have modified the existing authorization schemes, such as the ApiKeyAuthorization. Many have to keep their custom code in a forked repository, which is cumbersome in the long run.\n\nThe beef of this feature is in separated and optional JwtAuthorization module that can be included in index.html if JWT authentication is required. So there are only minimal changes in the Swagger UI itself. The module has been included in the example index.html.\n\nJwtAuthorization implements the following features: 1. Login with credentials 2. Fetch the JWT token from the login endpoint and perform a light token validation 3. Inject the token automatically in Swagger UI REST queries in the Authorization header.\n\nOne can activate the JWT authorization by using the securityDefinitions option in the swagger spec:\n\n``` JSON\n\"securityDefinitions\": {\n    \"jwt\": {\n        \"type\": \"jwt\",\n        \"authHeaderType\": \"JWT\",\n        \"tokenPropertyName\": \"access_token\",\n        \"authorizationUrl\": \"your-authserver-url.com/auth\",\n        \"description\": \"Please log in by using your email as an username.\"\n    }\n}\n```\n- The **\"type\"** option is _required_.\n- Option **\"authorizationUrl\"** is required. This defines URL to the REST endpoint which is used for the JWT authentication. The option respects the \"schemes\" protocol definitions, i.e. if \"scheme\":\"https\" or \"schemes\": [\"https\"] is used, 'https://' is injected automatically in front of the authorizationUrl.\n- Option **\"authHeaderType\"** is _optional_. It defines the token type of the injected Authorization header. The default value is _'Bearer'_, althought using _'JWT'_ is adviced.\n- Option **\"tokenPropertyName\"** is _optional_. This defines the property name which is used for getting the token data from the auth endpoint JSON response. The default value is _'access_token'_.\n\nOne can also customize how the login payload is structured in the client before it is sent to the server, by adding the following code snippet before loading the Swagger UI:\n\n``` JavaScript\n// This is the default behaviour of the module. \n// As result, payload {\"username\":\"yourUsername\",\"password\":\"yourPassword\"}' will be \n// sent to your authorization endpoint.\nJwtAuthorization.prototype.createPayload = function (username, password) {\n    return {\n        username: username,\n        password: password\n    };\n};\n\n// You can modify it to serve your needs:\nJwtAuthorization.prototype.createPayload = function (username, password) {\n    return {\n        email: username,\n        pwd: password\n    };\n};\n\n```\n"},"comment":{"url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/comments/299821638","html_url":"https://github.com/swagger-api/swagger-ui/pull/2234#issuecomment-299821638","issue_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/2234","id":299821638,"user":{"login":"pqzxc","id":27995824,"avatar_url":"https://avatars2.githubusercontent.com/u/27995824?v=3","gravatar_id":"","url":"https://api.github.com/users/pqzxc","html_url":"https://github.com/pqzxc","followers_url":"https://api.github.com/users/pqzxc/followers","following_url":"https://api.github.com/users/pqzxc/following{/other_user}","gists_url":"https://api.github.com/users/pqzxc/gists{/gist_id}","starred_url":"https://api.github.com/users/pqzxc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pqzxc/subscriptions","organizations_url":"https://api.github.com/users/pqzxc/orgs","repos_url":"https://api.github.com/users/pqzxc/repos","events_url":"https://api.github.com/users/pqzxc/events{/privacy}","received_events_url":"https://api.github.com/users/pqzxc/received_events","type":"User","site_admin":false},"created_at":"2017-05-08T09:43:05Z","updated_at":"2017-05-08T09:43:05Z","body":"I would also be very interested to hear if anyone has an answer to @OmgImAlexis's question."}}
{"actor":{"display_login":"pqzxc"}}