Skip to content

Handling of relative urls for Oauth2 authorizationUrl and tokenUrl #5243

@agateblue

Description

@agateblue

Q&A (please complete the following information)

  • OS: Linux
  • Browser: Firefox
  • Version: 65
  • Method of installation: Docker (via official hub image)
  • Swagger-UI version: v3.21.0
  • Swagger/OpenAPI version: 3.0.2

Content & configuration

I'm in the process of documenting my OAuth2 endpoints, and have the following definitions:

openapi: "3.0.2"
info:
  version: "1.0.0"
  title: "Funkwhale API"

servers:
  - url: https://demo.funkwhale.audio/api/v1
    description: Demo server
  - url: https://{domain}/api/v1
    description: Custom server
    variables:
      domain:
        default: yourdomain
        description: Your Funkwhale Domain
      protocol:
        enum:
          - 'http'
          - 'https'
        default: 'https'

components:
  securitySchemes:
    oauth:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: /authorize
          tokenUrl: /api/v1/oauth/token/

As you can see, I have multiple servers configured, with a dynamic domain, because my API can be deployed in multiple places. The authorizationUrl and tokenUrl are relative.

Describe the bug you're encountering

Based on what is described in Swagger's documentation:

Relative Endpoint URLs

In OpenAPI 3.0, authorizationUrl, tokenUrl and refreshUrl can be specified relative to the API server URL. This is handy if these endpoints are on same server as the rest of the API operations.

I expect the relative urls in the oauth definition to be resolved to the current API server. That is, if my server is https://demo.funkwhale.audio/api/v1, the authorization URL should be https://demo.funkwhale.audio/api/v1/authorize.

However, I don' observe that behaviour, and when trying to authenticate with OAuth, I'm redirected to http://localhost:8002/authorize instead. http://localhost:8002 is the url of my Swagger UI, so I think the relative url is actually resolved on the swagger UI URL, and not the current API server URL.

To reproduce...

Steps to reproduce the behavior:

  1. Add an oauth definition to your swagger.yml file with a relative URL as the autorizationUrl value
  2. Try to authenticate with oauth
  3. Observes that you are redirected to the relative URL you specified but on the Swagger UI host, instead of the API server.
  4. See error

Expected behavior

I expect the relative urls in the oauth definition to be resolved to the current API server. That is, if my server is https://demo.funkwhale.audio/api/v1, the authorization URL should be https://demo.funkwhale.audio/api/v1/authorize.

Additional context or thoughts

Let me know if you need any additional info :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions