{"action":"created","issue":{"url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/3953","repository_url":"https://api.github.com/repos/swagger-api/swagger-ui","labels_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/3953/labels{/name}","comments_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/3953/comments","events_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/3953/events","html_url":"https://github.com/swagger-api/swagger-ui/issues/3953","id":277299554,"number":3953,"title":"How to authenticate with OAuth2","user":{"login":"kopax","id":1866564,"avatar_url":"https://avatars0.githubusercontent.com/u/1866564?v=4","gravatar_id":"","url":"https://api.github.com/users/kopax","html_url":"https://github.com/kopax","followers_url":"https://api.github.com/users/kopax/followers","following_url":"https://api.github.com/users/kopax/following{/other_user}","gists_url":"https://api.github.com/users/kopax/gists{/gist_id}","starred_url":"https://api.github.com/users/kopax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kopax/subscriptions","organizations_url":"https://api.github.com/users/kopax/orgs","repos_url":"https://api.github.com/users/kopax/repos","events_url":"https://api.github.com/users/kopax/events{/privacy}","received_events_url":"https://api.github.com/users/kopax/received_events","type":"User","site_admin":false},"labels":[{"id":185046751,"url":"https://api.github.com/repos/swagger-api/swagger-ui/labels/Support","name":"Support","color":"bfe5bf","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2017-11-28T08:39:22Z","updated_at":"2018-02-06T18:44:21Z","closed_at":"2018-02-05T22:54:05Z","author_association":"NONE","body":"| Q                               | A\r\n| ------------------------------- | -------\r\n| Bug or feature request?         |  Help\r\n| Which Swagger/OpenAPI version?  | 2.0\r\n| Which Swagger-UI version?       | latest\r\n| How did you install Swagger-UI? |  npm install swagger-ui-dist --save\r\n| Which browser & version?        | chrome Version 61.0.3163.79 (Official Build) (64-bit)\r\n| Which operating system?         | Debian 8\r\n\r\n\r\nI have a **springboot** backend secured with **spring-security** and **spring-security-oauth2**  I have **springfox** installed. I am using the code grant flow specified in RFC6749.\r\n\r\nMy OAuth2 client is autoapproving so there is no redirection form to validate for the user.\r\n\r\nI have a reactjs app as a client and I want to install **swagger-ui** on it.\r\n\r\nI successfully managed to display the **swagger-ui**. The documentation says :\r\n\r\n> You can configure OAuth2 authorization by calling initOAuth method with passed configs under the instance of SwaggerUIBundle default client_id and client_secret, realm, an application name appName, scopeSeparator, additionalQueryStringParams, useBasicAuthenticationWithAccessCodeGrant.\r\n\r\nThe OAuth2 configuration explained in the documentation does not trigger any request to authenticate. \r\n\r\nThis is how my react page look like : \r\n\r\n```jsx\r\nimport React from 'react';\r\nimport { SwaggerUIBundle, SwaggerUIStandalonePreset } from \"swagger-ui-dist\"\r\nimport 'swagger-ui-dist/swagger-ui.css';\r\nimport { oAuthClient } from \"../../../config/index\";\r\nexport default class SwaggerUIPage extends React.PureComponent {\r\n  state = {\r\n    ui: null,\r\n  }\r\n  componentDidMount() {\r\n    this.initializeUi();\r\n  }\r\n  initializeUi() {\r\n    const { redirectUri } = oAuthClient;\r\n    const ui = SwaggerUIBundle({\r\n      url: `http://localhost:8080/v2/api-docs`,\r\n      dom_id: '#swagger-ui',\r\n      oauth2RedirectUrl: 'http://localhost:8080/redirect/cb',\r\n      presets: [\r\n        SwaggerUIBundle.presets.apis,\r\n        SwaggerUIStandalonePreset\r\n      ],\r\n      plugins: [\r\n        SwaggerUIBundle.plugins.DownloadUrl,\r\n        SwaggerUIBundle.plugins.AuthActions, // <-- Iam trying to add plugins in order to enable OAuth2 authentication\r\n        SwaggerUIBundle.plugins.AuthIndex,\r\n        SwaggerUIBundle.plugins.AuthReducers,\r\n        SwaggerUIBundle.plugins.AuthSelectors,\r\n        SwaggerUIBundle.plugins.AuthSpecWrapActions,\r\n      ],\r\n    });\r\n    this.setState({ ui }, this.initializeOAuth);\r\n  }\r\n\r\n  initializeOAuth() {\r\n    const { clientId, clientSecret, accessTokenUri, redirectUri } = oAuthClient;\r\n    console.log(oAuthClient);\r\n    console.log(SwaggerUIBundle.plugins);\r\n    // Method can be called in any place after calling constructor SwaggerUIBundle\r\n    const oauth = this.state.ui.initOAuth({\r\n      clientId,\r\n      clientSecret,\r\n      realm: 'api',\r\n      tokenUrl: 'http://localhost:8080/oauth/token',\r\n      oauth2RedirectUrl: 'http://localhost:8080/redirect/cb',\r\n      appName: 'reactapp',\r\n      scopeSeparator: ' ',\r\n      additionalQueryStringParams: { test: 'please help me login' },\r\n      useBasicAuthenticationWithAccessCodeGrant: true,\r\n      ...oAuthClient,\r\n    });\r\n    // console.log(window.opener.swaggerUIRedirectOauth2);\r\n    // oauth2.callback({auth: oauth2.auth, token: json, isValid: true}) // <-- I have found that in the distributed oauth2 page html in the dist package, I have tried to called `oauth2.callback` myself but I can't get `window.opener.swaggerUIRedirectOauth2`\r\n  }\r\n  render = () => <div id=\"swagger-ui\"/>\r\n}\r\n```\r\n\r\n\r\n### Expected Behavior\r\n\r\nI expect the OAuth configuration to be fulfilled\r\n\r\n### Current Behavior\r\n\r\nI have 401 Unauthorized when I test a secured endpoint and I don't see the `swagger-ui` trying to request my OAuth security endpoints.\r\n\r\n### Possible Solution\r\n\r\nNo idea.\r\n\r\n### Context\r\n\r\n1. How do you authenticate **swagger-ui** ?\r\n1. I can see sources that concern `redux` *(login action/reducer)* even If I don't see anywhere in the documentation where it says how to use it. Is there anything I a missing? Could you maybe share a more detailled example?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/comments/363523449","html_url":"https://github.com/swagger-api/swagger-ui/issues/3953#issuecomment-363523449","issue_url":"https://api.github.com/repos/swagger-api/swagger-ui/issues/3953","id":363523449,"user":{"login":"shockey","id":680248,"avatar_url":"https://avatars2.githubusercontent.com/u/680248?v=4","gravatar_id":"","url":"https://api.github.com/users/shockey","html_url":"https://github.com/shockey","followers_url":"https://api.github.com/users/shockey/followers","following_url":"https://api.github.com/users/shockey/following{/other_user}","gists_url":"https://api.github.com/users/shockey/gists{/gist_id}","starred_url":"https://api.github.com/users/shockey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shockey/subscriptions","organizations_url":"https://api.github.com/users/shockey/orgs","repos_url":"https://api.github.com/users/shockey/repos","events_url":"https://api.github.com/users/shockey/events{/privacy}","received_events_url":"https://api.github.com/users/shockey/received_events","type":"User","site_admin":false},"created_at":"2018-02-06T18:44:21Z","updated_at":"2018-02-06T18:44:21Z","author_association":"CONTRIBUTOR","body":"@kopax, sounds good, sorry you weren't able to get it working!\r\n\r\nwhen/if you pick the task back up, feel free to bump this issue or open a new one."}}
{"actor":{"display_login":"shockey"}}