Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger UI OAuth2 authorization code grant not working. #3947

Closed
kopax opened this issue Nov 26, 2017 · 3 comments
Closed

Swagger UI OAuth2 authorization code grant not working. #3947

kopax opened this issue Nov 26, 2017 · 3 comments

Comments

@kopax
Copy link

kopax commented Nov 26, 2017

Before all thanks for making swagger free, the tool look very nice.

I have installed swagger-ui-dist and I have created the following page in my React application:

import React from 'react';
import { SwaggerUIBundle, SwaggerUIStandalonePreset } from "swagger-ui-dist"
import 'swagger-ui-dist/swagger-ui.css';
// import 'swagger-ui-dist/oauth2-redirect.html';
import { oAuthClient } from "../../../config/index";
import messages from './messages';

export default class SwaggerUIPage extends React.PureComponent {

  state = {
    ui: null,
  }

  componentDidMount() {
    this.initializeUi();
  }

  initializeUi() {
    const { redirectUri } = oAuthClient;
    const ui = SwaggerUIBundle({
      url: `${redirectUri}/v2/api-docs`,
      dom_id: '#swagger-ui',
      oauth2RedirectUrl: redirectUri,
      presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset
      ],
      plugins: [
        SwaggerUIBundle.plugins.DownloadUrl,
        SwaggerUIBundle.plugins.AuthActions,
        SwaggerUIBundle.plugins.AuthIndex,
        SwaggerUIBundle.plugins.AuthReducers,
        SwaggerUIBundle.plugins.AuthSelectors,
        SwaggerUIBundle.plugins.AuthSpecWrapActions,
      ],
    });
    this.setState({ ui }, this.initializeOAuth);
  }

  initializeOAuth() {
    const { clientId, clientSecret, accessTokenUri, redirectUri } = oAuthClient;
    console.log(oAuthClient);
    console.log(SwaggerUIBundle.plugins)
    console.log(SwaggerUIBundle.presets)

    // Method can be called in any place after calling constructor SwaggerUIBundle
    const oauth = this.state.ui.initOAuth({
      clientId,
      clientSecret,
      realm: 'api',
      tokenUrl: accessTokenUri,
      oauth2RedirectUrl: redirectUri,
      redirectUri: 'http://localhost:8080/oauth/token',
      appName: 'backend-test',
      scopeSeparator: ' ',
      additionalQueryStringParams: { test: 'hello' },
      useBasicAuthenticationWithAccessCodeGrant: true,
      ...oAuthClient,
      scopeList: [],
    });
    console.log(oauth);
    // console.log(window.opener.swaggerUIRedirectOauth2);
    // oauth2.callback({auth: oauth2.auth, token: json, isValid: true});

  }



  render() {
    return (
      <div id="swagger-ui"/>
    );
  }

}

I've also tried to add the content of oauth2-redirect.html in my react scope.

Because I don't know what to do. I don't see any authentication request going anywhere, I don't find much in the documentation and I see a lot of written code for plugins.

I am using the authorization code grant flow, and I already have the jwt in my app, is there a way to quickly provide it to swagger client ?

@shockey
Copy link
Contributor

shockey commented Nov 29, 2017

Hey @kopax, you raised what looks like the same question in #3953, so I'm going to close this and get back to you in #3953.

Let me know if I read the two issues incorrectly. Thanks! 😄

@shockey shockey closed this as completed Nov 29, 2017
@kopax
Copy link
Author

kopax commented Nov 29, 2017

@shockey this issue concerned my impossibility to complete the installation with OAuth2.
#3953 is an issue about Unit test failing for latest react and enzyme version. We can track both in #3953 for sure.

@shockey
Copy link
Contributor

shockey commented Dec 19, 2017

Closing in favor of #3953

@lock lock bot locked and limited conversation to collaborators Jul 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants