backstage: Bug in oauth2 authentication from Swagger API definitions - invalid redirect uri

Expected Behavior

I would expect to be able to login to spotify API via oauth and play with it

Actual Behavior

When I log in Iget a page with “invalid redirect uri”

Steps to Reproduce

  1. Create a new backstage app (my is version 1.1.0)
  2. Start it and go to API and choose spotify API
  3. Click authenticate and type in you clientID and secret and login
  4. you’ll get 404 “INVALID_CLIENT: Invalid redirect URI”

Context

I cannot connect to my own API’s anymore. I discovered it after upgrade from 0.4.3 to 1.0.3. And suddenly oauth2 was not working. It seems that the path to swagger page is included in redirect url like: https://localhost:3000/catalog/default/api/spotify/oauth2-redirect.html. It was in my old version https://localhost:3000/oauth2-redirect.html

Your Environment

  • Browser Information: Google Chrome 101.0.4951.54

  • Output of yarn backstage-cli info:

OS: Windows_NT 10.0.22000 - win32/x64 node: v14.17.1 yarn: 1.22.17 cli: 0.17.0 (installed)

Dependencies: @backstage/app-defaults 1.0.1 @backstage/backend-common 0.13.2 @backstage/backend-tasks 0.3.0 @backstage/catalog-client 1.0.1 @backstage/catalog-model 1.0.1 @backstage/cli-common 0.1.8 @backstage/cli 0.17.0 @backstage/config-loader 1.1.0 @backstage/config 1.0.0 @backstage/core-app-api 1.0.1 @backstage/core-components 0.9.3 @backstage/core-plugin-api 1.0.1 @backstage/errors 1.0.0 @backstage/integration-react 1.0.1 @backstage/integration 1.1.0 @backstage/plugin-api-docs 0.8.4 @backstage/plugin-app-backend 0.3.31 @backstage/plugin-auth-backend 0.13.0 @backstage/plugin-auth-node 0.2.0 @backstage/plugin-catalog-backend 1.1.1 @backstage/plugin-catalog-common 1.0.1 @backstage/plugin-catalog-graph 0.2.16 @backstage/plugin-catalog-import 0.8.7 @backstage/plugin-catalog-react 1.0.1 @backstage/plugin-catalog 1.1.0 @backstage/plugin-github-actions 0.5.4 @backstage/plugin-org 0.5.4 @backstage/plugin-permission-common 0.6.0 @backstage/plugin-permission-node 0.6.0 @backstage/plugin-permission-react 0.4.0 @backstage/plugin-proxy-backend 0.2.25 @backstage/plugin-scaffolder-backend 1.1.0 @backstage/plugin-scaffolder-common 1.0.1 @backstage/plugin-scaffolder 1.1.0 @backstage/plugin-search-backend-node 0.6.0 @backstage/plugin-search-backend 0.5.1 @backstage/plugin-search-common 0.3.3 @backstage/plugin-search-react 0.1.0 @backstage/plugin-search 0.8.0 @backstage/plugin-tech-radar 0.5.11 @backstage/plugin-techdocs-backend 1.1.0 @backstage/plugin-techdocs-node 1.1.0 @backstage/plugin-techdocs-react 0.1.0 @backstage/plugin-techdocs 1.1.0 @backstage/plugin-user-settings 0.4.3 @backstage/release-manifests 0.0.2 @backstage/search-common 0.3.3 @backstage/test-utils 1.0.1 @backstage/theme 0.2.15 @backstage/types 1.0.0 @backstage/version-bridge 1.0.1 Done in 0.70s.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 26 (18 by maintainers)

Most upvoted comments

As an intermediate solution, which works for me, you can do the next:

  1. in the root package.json add
"resolutions": {
    "**/swagger-ui-react": "4.1.0"
}
  1. Then cd ./packages/app && yarn add btoa
  2. Then cd ../../ && yarn install

With this I make it to use the old version, where that improvement was not yet applied.

seem like this might be an approach to resolve it for you: https://github.com/backstage/backstage/pull/15531#issuecomment-1424693056

@thatguysimon tbh, no idea. There was a PR referenced above which got closed unmerged. However, at a quick glance, it didn’t seem to be focused on this issue. I assume there was the idea that it could be used for it, potentially.

plugins/api-docs/src/components/OpenApiDefinitionWidget/OpenApiDefinition.tsx

contains

<SwaggerUI spec={def} url="" deepLinking />

and SwaggerUI has the optional property oauth2RedirectUrl.

Currently, only a definition gets passed. No other properties are used. (see OpenApiDefinitionProps)

OpenApiDefinition itself is used as part of LazyOpenApiDefinition used as part of OpenApiDefinitionWidget with OpenApiDefinitionWidgetProps only containing the definition as well.

And ultimately, it’s used at plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionWidget.tsx, again passing only the definition. It is used as part of the implementation of ApiDocsConfig.getApiDefinitionWidget (plugins/api-docs/src/config.ts, plugins/api-docs/src/plugin.ts)

Seems like there is still a need to define and implement, where the value has to come from and how this setting can be provided.

There’s some swagger work happening in #15531 which also discusses a way to pass this in as options. There might be good to be know in case it could solve both needs.

I’m a rookie javascript developer but I’ll give it a shot next week after Danish holliday