個別の操作にOAuth2パスワードフローを使用

操作の認証にOAuth2パスワードフローを使うと、クライアントがユーザーのパスワードを直接送信します。

説明

OAuth2 の password フローでは、クライアントが利用者のパスワードを直接受け取ります。RFC 9700 はこのフローの使用を禁止しています。

想定される影響

再利用可能なパスワードがクライアントに渡り、MFA など複数の手順を伴う認証にも対応しにくくなります。

対処方法

対話型ログインでは、クライアントと認可サーバーを PKCE を使う認可コードフローに移行します。flow を accessCode に変更し、プロバイダーの HTTPS エンドポイントと操作に必要なスコープを設定してください。

例

例の GET / は変更後も petstore_auth の read:api スコープを要求します。

変更前

json
{
  "swagger": "2.0",
  "paths": {
    "/": {
      "get": {
        "security": [
          {
            "petstore_auth": [
              "read:api"
            ]
          }
        ]
      }
    }
  },
  "securityDefinitions": {
    "petstore_auth": {
      "type": "oauth2",
      "flow": "password",
      "tokenUrl": "https://api.my.company.com/oauth/token",
      "scopes": {
        "read:api": "read your apis"
      }
    }
  }
}

変更後

json
{
  "swagger": "2.0",
  "paths": {
    "/": {
      "get": {
        "security": [
          {
            "petstore_auth": [
              "read:api"
            ]
          }
        ]
      }
    }
  },
  "securityDefinitions": {
    "petstore_auth": {
      "type": "oauth2",
      "flow": "accessCode",
      "authorizationUrl": "https://api.my.company.com/oauth/authorize",
      "tokenUrl": "https://api.my.company.com/oauth/token",
      "scopes": {
        "write:api": "modify apis in your account",
        "read:api": "read your apis"
      }
    }
  }
}

参考資料