説明
OpenAPI 3.0の操作のsecurityが、対応するOAuth2方式のflowsにないスコープを参照すると、その操作に必要な権限が文書の定義と一致しなくなります。
想定される影響
APIの利用者が誤ったスコープでトークンを要求したり、操作に必要な権限を誤って実装したりする可能性があります。
対処方法
操作で要求するスコープを、components.securitySchemes内のOAuth2のscopesと認可サーバーの設定に合わせます。必要な権限の定義が抜けていれば追加してください。操作の要件は全体のsecurityを置き換えるため、引き続き必要な権限も維持します。
例
この例では、操作から不要なerror:apiの参照を削除しています。OpenID Connectのスコープは、ローカルのOAuth2フローの定義ではなく、プロバイダーの設定と照合してください。
変更前
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"security": [
{
"oAuth2AuthCode": [
"read:api",
"error:api"
]
}
]
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCode": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://api.example.com/oauth/authorize",
"tokenUrl": "https://api.example.com/oauth/token",
"scopes": {
"read:api": "read your apis"
}
}
}
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"security": [
{
"oAuth2AuthCode": [
"read:api"
]
}
]
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCode": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://api.example.com/oauth/authorize",
"tokenUrl": "https://api.example.com/oauth/token",
"scopes": {
"read:api": "read your apis"
}
}
}
}
}
}
}