security requirement에 잘못된 스코프를 사용하는 경우

OpenAPI 3.0에서 OAuth2와 OpenID Connect 이외의 인증 방식에는 스코프를 지정하지 않습니다.

설명

OpenAPI 3.0의 security에서 apiKey와 http 스킴의 값은 빈 배열 []입니다. 필요한 스코프는 oauth2 또는 openIdConnect 스킴에 지정하세요.

잠재적 영향

스코프를 지원하지 않는 스킴에 권한을 나열하면 문서 검증이 실패하거나 클라이언트가 지원되지 않는 권한을 요청할 수 있습니다.

해결 방법

각 스킴이 실제로 허용하는 인증 방식과 권한을 확인하세요. OAuth2 인가 코드 흐름을 사용하는 클라이언트에는 PKCE를 적용하세요.

예시

예시 문서는 api_key와 petstore_auth를 두 가지 인증 대안으로 선언합니다. API 키에는 스코프가 없고 OAuth2를 선택하면 write:pets와 read:pets가 모두 필요합니다.

변경 전

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "security": [
    {
      "api_key": [
        "write:api",
        "read:api"
      ]
    },
    {
      "petstore_auth": [
        "write:pets",
        "read:pets"
      ]
    }
  ],
  "paths": {},
  "components": {
    "securitySchemes": {
      "api_key": {
        "type": "apiKey",
        "name": "api_key",
        "in": "header"
      },
      "petstore_auth": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://example.org/api/oauth/dialog",
            "tokenUrl": "https://example.org/api/oauth/token",
            "scopes": {
              "write:pets": "modify pets in your account",
              "read:pets": "read your pets"
            }
          }
        }
      }
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "security": [
    {
      "api_key": []
    },
    {
      "petstore_auth": [
        "write:pets",
        "read:pets"
      ]
    }
  ],
  "paths": {},
  "components": {
    "securitySchemes": {
      "api_key": {
        "type": "apiKey",
        "name": "api_key",
        "in": "header"
      },
      "petstore_auth": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://example.org/api/oauth/dialog",
            "tokenUrl": "https://example.org/api/oauth/token",
            "scopes": {
              "write:pets": "modify pets in your account",
              "read:pets": "read your pets"
            }
          }
        }
      }
    }
  }
}

참조