작업별 보안 설정에 정의되지 않은 OAuth Scope 사용

OpenAPI 2.0의 작업별 보안 설정에서 정의되지 않은 OAuth2 스코프를 참조합니다.

설명

Swagger 2.0에서는 작업의 security가 전역 요구사항을 대체합니다. 작업에 필요한 스코프를 securityDefinitions 안의 해당 OAuth2 스킴에 정의하세요.

잠재적 영향

작업이 발급되지 않는 스코프를 요구하면 정상 클라이언트도 필요한 토큰을 받지 못할 수 있습니다.

해결 방법

작업이 요구하는 이름을 스킴의 scopes 및 인가 서버 설정과 대조해 오타를 고치세요. 실제 권한을 유지한 뒤 테스트 토큰으로 작업이 필요한 스코프를 확인하는지 검증하세요.

예시

GET /는 read:api를 유지하고 error:api를 제거합니다. error:api도 필요하면 해당 스코프를 정의하고 요구사항에 남기세요.

변경 전

yaml
swagger: "2.0"
paths:
  /:
    get:
      security:
        - oAuth2AuthCode:
            - read:api
            - error:api
securityDefinitions:
  oAuth2AuthCode:
    type: oauth2
    flow: accessCode
    authorizationUrl: https://api.example.com/oauth/authorize
    tokenUrl: https://api.example.com/oauth/token
    scopes:
      read:api: read your apis

변경 후

yaml
swagger: "2.0"
paths:
  /:
    get:
      security:
        - oAuth2AuthCode:
            - read:api
securityDefinitions:
  oAuth2AuthCode:
    type: oauth2
    flow: accessCode
    authorizationUrl: https://api.example.com/oauth/authorize
    tokenUrl: https://api.example.com/oauth/token
    scopes:
      read:api: read your apis

참조