OAuth2 scopes used with non-OAuth2 authentication

Basic and API key authentication in OpenAPI 2.0 require an empty scope array in security requirements.

Description

In Swagger 2.0, use an empty array [] for a basic or apiKey scheme named in security.

Potential impact

Listing scopes can fail validation or lead clients to expect permissions the scheme does not provide.

Remediation

If access depends on OAuth2 scopes, define and reference an OAuth2 scheme that matches the authorization server. Check which credentials the API actually requires.

Examples

Setting petstore_auth: [] removes the write and read scopes. Basic authentication is still required.

Before

yaml
swagger: "2.0"
security:
  - petstore_auth:
      - write
      - read
securityDefinitions:
  petstore_auth:
    type: basic

After

yaml
swagger: "2.0"
security:
  - petstore_auth: []
securityDefinitions:
  petstore_auth:
    type: basic

References