Invalid OAuth2 token URL in OpenAPI 2.0

tokenUrl must identify the OAuth2 provider's correct token endpoint.

Description

For OpenAPI 2.0 OAuth2 flows that use a token endpoint, such as accessCode, tokenUrl is where the client requests tokens. The implicit flow has no token endpoint.

Potential impact

A wrong address can prevent token issuance. HTTP or an unintended destination can expose credentials or tokens.

Remediation

Set the flow’s tokenUrl in securityDefinitions to the provider’s official HTTPS token endpoint, without a URL fragment (#). Verify that the client connects to that server and validates its certificate.

Examples

The example changes only tokenUrl for accessCode. Users still sign in through authorizationUrl.

Before

yaml
swagger: "2.0"
securityDefinitions:
  petstore_auth:
    type: oauth2
    flow: accessCode
    authorizationUrl: https://api.my.company.com/oauth/authorize
    tokenUrl: http://example.com#@evil.com/
    scopes:
      write:pets: modify pets
      read:pets: read pets

After

yaml
swagger: "2.0"
securityDefinitions:
  petstore_auth:
    type: oauth2
    flow: accessCode
    authorizationUrl: https://api.my.company.com/oauth/authorize
    tokenUrl: https://api.my.company.com/oauth/token
    scopes:
      write:pets: modify pets
      read:pets: read pets

References