OpenAPI Bearer Token & OAuth 2.0 Security Schemes Example

How to declare securitySchemes and operation-level security requirements in OpenAPI 3.0 specs.

Problem Statement

Undocumented security schemes prevent client code generators and automated testing tools from configuring authentication headers properly.

❌ Anti-Pattern / Bad Implementation

No components.securitySchemes defined; endpoints lack authorization requirements.

bad-pattern.yaml
paths:
  /v1/protected-data:
    get:
      summary: Protected endpoint

✓ Refactored / Recommended Implementation

Explicit Bearer JWT securityScheme attached to globally or operationally scoped security blocks.

good-pattern.yaml
openapi: 3.0.3
paths:
  /v1/protected-data:
    get:
      summary: Protected data resource
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Success
        '401':
          description: Unauthorized
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

How APIForge Checks This

  • Checks for global and path security requirement declarations
  • Validates securityScheme component configurations

Test your own OpenAPI specification against these checks

Paste any OpenAPI specification URL or YAML file into APIForge for instant 0-100 quality scoring, schema linting, and zero-CORS proxy testing.

Run API Score Check →
Share:𝕏 Postin Share