BasicAuth(basic_authモジュール)での認証フロー
core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php
floodにIPでのBasic認証失敗が許容内か問い合わせ
Userを取得
floodに該当UserでのBasic認証失敗が許容内か問い合わせ
※{uid}_{IPアドレス}のキーでfloodに登録されている
※(uid_onlyが有効(初期値:無効)になっているときは{uid}のみのキーで登録されている)User認証を実行
→成功:UserEntityを返却
→失敗:floodに失敗を登録
設定yml
core/modules/user/config/install/user.flood.yml
- IP:イベントに対して、1時間に50回の失敗まで許容
- USER:イベントに対して、6時間に5回の失敗まで許容
※今回の例でのイベントは「basic_auth.failed_login_ip」
なぜ「flood=洪水」という名前なのか気になったので調べてみたらそういう事かと納得。
http://e-words.jp/w/%E3%83%95%E3%83%A9%E3%83%83%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0.html
routing.ymlでのbasic_authの設定例
yml
mymodule.some.route:
path: '/hello/drupal'
defaults:
_controller: '\Drupal\mymodule\Controller\HelloController::hello'
options:
_auth: ['basic_auth']
requirements:
_permission: 'access content'
_method: 'GET'
上記例ではUserに付随する情報(RoleやPermission)を指定していないのであまり意味はない。
参考
Protecting Your Drupal 8 Resources
OAuthモジュールもあるらしい。Structure of routes
routing.ymlの書き方などについて