66namespace Magento \Backend \Controller \Adminhtml \Auth ;
77
88use Magento \Backend \App \Area \FrontNameResolver ;
9+ use Magento \Backend \App \BackendAppList ;
910use Magento \Backend \Model \UrlFactory ;
1011use Magento \Framework \App \Action \HttpGetActionInterface as HttpGet ;
1112use Magento \Framework \App \Action \HttpPostActionInterface as HttpPost ;
1213use Magento \Framework \App \ObjectManager ;
14+ use Magento \Framework \App \Request \Http ;
1315
1416/**
1517 * @api
@@ -27,6 +29,11 @@ class Login extends \Magento\Backend\Controller\Adminhtml\Auth implements HttpGe
2729 */
2830 private $ frontNameResolver ;
2931
32+ /**
33+ * @var BackendAppList
34+ */
35+ private $ backendAppList ;
36+
3037 /**
3138 * @var UrlFactory
3239 */
@@ -44,11 +51,13 @@ public function __construct(
4451 \Magento \Backend \App \Action \Context $ context ,
4552 \Magento \Framework \View \Result \PageFactory $ resultPageFactory ,
4653 FrontNameResolver $ frontNameResolver = null ,
54+ BackendAppList $ backendAppList = null ,
4755 UrlFactory $ backendUrlFactory = null
4856 ) {
4957 $ this ->resultPageFactory = $ resultPageFactory ;
5058 parent ::__construct ($ context );
5159 $ this ->frontNameResolver = $ frontNameResolver ?? ObjectManager::getInstance ()->get (FrontNameResolver::class);
60+ $ this ->backendAppList = $ backendAppList ?? ObjectManager::getInstance ()->get (BackendAppList::class);
5261 $ this ->backendUrlFactory = $ backendUrlFactory ?? ObjectManager::getInstance ()->get (UrlFactory::class);
5362 }
5463
@@ -96,9 +105,17 @@ private function getRedirect($path)
96105 */
97106 private function isValidBackendUri (): bool
98107 {
99- $ backendFrontName = $ this ->frontNameResolver ->getFrontName ();
100108 $ requestUri = $ this ->getRequest ()->getRequestUri ();
109+ $ backendApp = $ this ->backendAppList ->getCurrentApp ();
101110 $ baseUrl = parse_url ($ this ->backendUrlFactory ->create ()->getBaseUrl (), PHP_URL_PATH );
111+ if (!$ backendApp ) {
112+ $ backendFrontName = $ this ->frontNameResolver ->getFrontName ();
113+ } else {
114+ //In case of application authenticating through the admin login, the script name should be removed
115+ //from the path, because application has own script.
116+ $ baseUrl = Http::getUrlNoScript ($ baseUrl );
117+ $ backendFrontName = $ backendApp ->getCookiePath ();
118+ }
102119
103120 return strpos ($ requestUri , $ baseUrl . $ backendFrontName ) === 0 ;
104121 }
0 commit comments