操作のセキュリティ要件で参照される未定義のOAuth2スコープ

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

参考資料