説明
最上位の security は API のデフォルトの認証要件です。省略する場合は、保護する操作ごとに要件を指定します。
想定される影響
操作にも要件がないと、クライアントは認証情報を送る必要があるか判断できません。
対処方法
共通の要件は最上位の security に、例外は該当する操作に設定します。スキームは OpenAPI 3.0 の components.securitySchemes または 2.0 の securityDefinitions に定義し、サーバーでも同じポリシーを適用してください。
例
例の GET / は全体の petstore_auth を継承します。OAuth2 の URL はプロバイダーのエンドポイントに置き換えてください。 ペット用のスコープ名は例です。実際の操作に必要なスコープだけを要求してください。
変更前
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"components": {
"securitySchemes": {
"petstore_auth": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
}
}
}
}