{"id":1542,"date":"2021-09-19T10:06:51","date_gmt":"2021-09-19T01:06:51","guid":{"rendered":"https:\/\/blog.fourthgate.jp\/?p=1542"},"modified":"2021-09-19T10:06:51","modified_gmt":"2021-09-19T01:06:51","slug":"cakephp4%e3%81%aeauthentication%e3%81%a7%e8%a4%87%e6%95%b0%e3%81%ae%e8%aa%8d%e8%a8%bc","status":"publish","type":"post","link":"https:\/\/blog.fourthgate.jp\/?p=1542","title":{"rendered":"CakePHP4\u306eAuthentication\u3067\u8907\u6570\u306e\u8a8d\u8a3c"},"content":{"rendered":"<p>CakePHP4\u3067\u3001\u7ba1\u7406\u8005\u5411\u3051\u306e\u8a8d\u8a3c\u3068\u4e00\u822c\u30e6\u30fc\u30b6\u30fc\u5411\u3051\u306e\u8a8d\u8a3c\u3092\u8a2d\u7f6e\u3057\u305f\u3044\u5834\u5408\u306b\u3064\u3044\u3066\u30fb\u30fb\u30fb<\/p>\n<p>\u7ba1\u7406\u753b\u9762\u306f \/admin \u4ee5\u4e0b\u306b\u3042\u308b\u3068\u3057\u307e\u3059\uff08route.php\u3067prefix\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u3068\u3057\u3066\uff09\u3002<\/p>\n<p>Application.php \u306e getAuthenticationService \u3067\u3001url\u304c\/admin\u3067\u59cb\u307e\u3063\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3067\u51e6\u7406\u3092\u5207\u308a\u5206\u3051\u307e\u3059\u3002<\/p>\n<p><code><br \/>\nif ( preg_match( '\/^\\\/admin\\\/?\/', $path )  ) {<br \/>\n\u301c\u301c\u301c<br \/>\n$service-&gt;loadAuthenticator('Authentication.Session', [<br \/>\n'sessionKey' =&gt; 'ManagementAuth',   \/\/  \u7ba1\u7406\u8005\u8a8d\u8a3c\u306b\u4f7f\u7528\u3059\u308b\u30bb\u30c3\u30b7\u30e7\u30f3\u30ad\u30fc<br \/>\n] );<br \/>\n$service-&gt;loadIdentifier('Authentication.Password',<br \/>\n[<br \/>\n'fields' =&gt; $fields,<br \/>\n'resolver' =&gt; [<br \/>\n'className' =&gt; 'Authentication.Orm',<br \/>\n'userModel' =&gt; 'Adminusers',<br \/>\n],<br \/>\n]<br \/>\n);<br \/>\n\u301c\u301c\u301c<br \/>\n} else {<br \/>\n\u301c\u301c\u301c<br \/>\n$service-&gt;loadAuthenticator('Authentication.Session', [<br \/>\n'sessionKey' =&gt; 'MemberAuth',   \/\/  \u7ba1\u7406\u8005\u8a8d\u8a3c\u3068\u306f\u5225\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u30ad\u30fc\u3092\u8a2d\u5b9a<br \/>\n] );<br \/>\n$service-&gt;loadIdentifier('Authentication.Password',<br \/>\n[<br \/>\n'fields' =&gt; $fields,<br \/>\n'resolver' =&gt; [<br \/>\n'className' =&gt; 'Authentication.Orm',<br \/>\n'userModel' =&gt; 'Users',<br \/>\n],<br \/>\n]<br \/>\n);<br \/>\n\u301c\u301c\u301c<br \/>\n}<\/code><\/p>\n<p>\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u3001\/admin \u4ee5\u4e0b\u3067\u52d5\u304f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u306f\u3001Adminusers \u30e2\u30c7\u30eb\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n\u305d\u308c\u4ee5\u5916\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u306f\u3001Users \u30e2\u30c7\u30eb\u3092\u4f7f\u3063\u3066\u8a8d\u8a3c\u3057\u307e\u3059\u3002<\/p>\n<p>\u3082\u3063\u3068\u30b9\u30de\u30fc\u30c8\u306a\u65b9\u6cd5\u304c\u3042\u308b\u3093\u3060\u308d\u3046\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3068\u308a\u3042\u3048\u305a\u3001\u3053\u308c\u3067\u3046\u307e\u304f\u3044\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CakePHP4\u3067\u3001\u7ba1\u7406\u8005\u5411\u3051\u306e\u8a8d\u8a3c\u3068\u4e00\u822c\u30e6\u30fc\u30b6\u30fc\u5411\u3051\u306e\u8a8d\u8a3c\u3092\u8a2d\u7f6e\u3057\u305f\u3044\u5834\u5408\u306b\u3064\u3044\u3066\u30fb\u30fb\u30fb \u7ba1\u7406\u753b\u9762\u306f \/admin \u4ee5\u4e0b\u306b\u3042\u308b\u3068\u3057\u307e\u3059\uff08route.php\u3067prefix\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u3068\u3057\u3066\uff09\u3002 Application. &hellip; <a href=\"https:\/\/blog.fourthgate.jp\/?p=1542\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1542","post","type-post","status-publish","format-standard","hentry","category-web"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/posts\/1542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1542"}],"version-history":[{"count":4,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/posts\/1542\/revisions"}],"predecessor-version":[{"id":1546,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/posts\/1542\/revisions\/1546"}],"wp:attachment":[{"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}