rapi-doc / RapiDoc

RapiDoc -WebComponent for OpenAPI Spec
https://rapidocweb.com
MIT License
1.61k stars 271 forks source link

URI redirect problem with oAuth #1011

Open BossHogg97 opened 1 month ago

BossHogg97 commented 1 month ago

Hi, i'm integrating Rapidoc in a fastify server. I'm using keycloak with oAuth. I'm facing the following issue. When i click on authorization, and i setup the client-id the keycloak login page opens. After i insert username and password there's no automatically redirect to rapidoc page. Furthermore, if i go back to rapidoc page manually and i try to execute an API request the response is 401 unauthorized.

Following the openApi specification:

...
securitySchemes: {
            oauth2: {
              type: 'oauth2',
              description: 'This API uses OAuth 2 with the authorizationCode grant flow',
              flows: {
                authorizationCode: {
                  authorizationUrl: `${process.env.KEYCLOAK_BASE_URL}/realms/XXXX/protocol/openid-connect/auth`,
                  tokenUrl: `${process.env.KEYCLOAK_BASE_URL}/realms/XXXX/protocol/openid-connect/token`,
                  scopes: {}
                }
              }
            },
          }
        },
        security: [
          {
            oauth2: [],
          }
        ]
}
...

Here the index.html file where rapidoc is defined

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name='viewport' content='width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes'>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&family=Roboto+Mono&display=swap" rel="stylesheet">
    <script type="module" src="https://unpkg.com/rapidoc/dist/rapidoc-min.js"></script>
    <style>
    </style>
  </head>
  <body>
    <rapi-doc spec-url="./swagger/json">
    </rapi-doc>
  </body>
</html>

In the same folder where index.html is defined i have the oauth-receiver.html file

<!doctype html>
<html>
    <head>
        <script type="module" src="https://unpkg.com/rapidoc/dist/rapidoc-min.js"></script>
    </head>

    <body>
        <oauth-receiver> </oauth-receiver>
    </body>
</html>

I read the following doc: https://rapidocweb.com/oauth_instructions.html#auth-receiver-html

Furthermore, if I don't define a route /oauth-receiver.html I get an error: route not found by fastify. How can i fix this problem? Thanks