How to programmatically login an admin user?How to perform auto-login in Magento2 admin?Login to multiple magento admin panelHow to force a admin user to change their password?Can't login to Magento admin after migrationAdmin Not Redirecting After LoginHow to log in an admin user programmatically from frontend controller in Magento 2How to perform auto-login in Magento2 admin?Testing magento 2 admin user _isAllowedWhy are my images being loaded as the Admin Login page?Backend admin login programmaticallyNot having the page reload or being redirected if the login credentials are wrong - Magento 2.2
How did old MS-DOS games utilize various graphic cards?
I have a problem assistant manager, but I can't fire him
How to produce a more sophisticated pie chart?
Certain search in list
SQL counting distinct over partition
What to do when surprise and a high initiative roll conflict with the narrative?
What makes Ada the language of choice for the ISS's safety-critical systems?
How to manually rewind film?
Electricity free spaceship
Active low-pass filters --- good to what frequencies?
Implement Own Vector Class in C++
Does the Long March-11 increase its thrust after clearing the launch tower?
How can this tool find out registered domains from an IP?
Getting UPS Power from One Room to Another
A IP can traceroute to it, but can not ping
Group Integers by Originality
Does a scale have more than seven chords?
How to tell your grandparent to not come to fetch you with their car?
What is the `some` keyword in SwiftUI?
Is using haveibeenpwned to validate password strength rational?
English word for "product of tinkering"
is it possible for a vehicle to be manufactured witout a catalitic converter
Why can my keyboard only digest 6 keypresses at a time?
How to use memset in c++?
How to programmatically login an admin user?
How to perform auto-login in Magento2 admin?Login to multiple magento admin panelHow to force a admin user to change their password?Can't login to Magento admin after migrationAdmin Not Redirecting After LoginHow to log in an admin user programmatically from frontend controller in Magento 2How to perform auto-login in Magento2 admin?Testing magento 2 admin user _isAllowedWhy are my images being loaded as the Admin Login page?Backend admin login programmaticallyNot having the page reload or being redirected if the login credentials are wrong - Magento 2.2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am on Magento 2.3.1 and I am trying to login an admin user automatically given their username. I have tried using the MagentoBackendModelAuthSession
class like this:
$this->_authSession->setUser($adminUserName);
$this->_authSession->processLogin();
$this->_authSession->refreshAcl();
$this->_authSession->prolong();
and then redirecting like this:
return $this->_backendUrl->getUrl('admin/dashboard/index');
but it keeps giving me the login prompt instead of the dashboard even though this test:
var_dump($this->_authSession->isLoggedIn());
returns the boolean True.
Any help would be appreciated
magento2 admin magento2.3 admin-login admin-user
New contributor
add a comment |
I am on Magento 2.3.1 and I am trying to login an admin user automatically given their username. I have tried using the MagentoBackendModelAuthSession
class like this:
$this->_authSession->setUser($adminUserName);
$this->_authSession->processLogin();
$this->_authSession->refreshAcl();
$this->_authSession->prolong();
and then redirecting like this:
return $this->_backendUrl->getUrl('admin/dashboard/index');
but it keeps giving me the login prompt instead of the dashboard even though this test:
var_dump($this->_authSession->isLoggedIn());
returns the boolean True.
Any help would be appreciated
magento2 admin magento2.3 admin-login admin-user
New contributor
want to login in admin panel programmaticlly?
– Asad Khan
May 31 at 11:35
yes, I am trying to automatically log into the admin panel
– user79886
May 31 at 11:40
add a comment |
I am on Magento 2.3.1 and I am trying to login an admin user automatically given their username. I have tried using the MagentoBackendModelAuthSession
class like this:
$this->_authSession->setUser($adminUserName);
$this->_authSession->processLogin();
$this->_authSession->refreshAcl();
$this->_authSession->prolong();
and then redirecting like this:
return $this->_backendUrl->getUrl('admin/dashboard/index');
but it keeps giving me the login prompt instead of the dashboard even though this test:
var_dump($this->_authSession->isLoggedIn());
returns the boolean True.
Any help would be appreciated
magento2 admin magento2.3 admin-login admin-user
New contributor
I am on Magento 2.3.1 and I am trying to login an admin user automatically given their username. I have tried using the MagentoBackendModelAuthSession
class like this:
$this->_authSession->setUser($adminUserName);
$this->_authSession->processLogin();
$this->_authSession->refreshAcl();
$this->_authSession->prolong();
and then redirecting like this:
return $this->_backendUrl->getUrl('admin/dashboard/index');
but it keeps giving me the login prompt instead of the dashboard even though this test:
var_dump($this->_authSession->isLoggedIn());
returns the boolean True.
Any help would be appreciated
magento2 admin magento2.3 admin-login admin-user
magento2 admin magento2.3 admin-login admin-user
New contributor
New contributor
New contributor
asked May 31 at 11:09
user79886user79886
52
52
New contributor
New contributor
want to login in admin panel programmaticlly?
– Asad Khan
May 31 at 11:35
yes, I am trying to automatically log into the admin panel
– user79886
May 31 at 11:40
add a comment |
want to login in admin panel programmaticlly?
– Asad Khan
May 31 at 11:35
yes, I am trying to automatically log into the admin panel
– user79886
May 31 at 11:40
want to login in admin panel programmaticlly?
– Asad Khan
May 31 at 11:35
want to login in admin panel programmaticlly?
– Asad Khan
May 31 at 11:35
yes, I am trying to automatically log into the admin panel
– user79886
May 31 at 11:40
yes, I am trying to automatically log into the admin panel
– user79886
May 31 at 11:40
add a comment |
1 Answer
1
active
oldest
votes
This is what i managed to do (based on How to perform auto-login in Magento2 admin?) and is working
?php
require __DIR__ . '/app/bootstrap.php';
class TestApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
$this->_eventManager = $this->_objectManager->get('MagentoFrameworkEventManager');
$this->_areaList = $this->_objectManager->get('MagentoFrameworkAppAreaList');
$this->_request = $this->_objectManager->get('MagentoFrameworkAppRequestHttp');
$this->_response = $this->_objectManager->get('MagentoFrameworkAppResponseHttp');
$this->_configLoader = $this->_objectManager->get('MagentoFrameworkObjectManagerConfigLoaderInterface');
$this->_state = $this->_objectManager->get('MagentoFrameworkAppState');
$this->_filesystem = $this->_objectManager->get('MagentoFrameworkFilesystem');
$this->registry = $this->_objectManager->get('MagentoFrameworkRegistry');
parent::__construct($objectManager, $this->_eventManager, $this->_areaList, $this->_request, $this->_response, $this->_configLoader, $this->_state, $this->_filesystem, $this->registry);
public function launch()
$areaCode = 'adminhtml';
$username = 'superadmin3';
$this->_state->setAreaCode($areaCode);
$this->_request->setPathInfo('/admin');
$this->_objectManager->configure($this->_configLoader->load($areaCode));
/** @var MagentoUserModelUser $user */
$user = $this->_objectManager->get('MagentoUserModelUser')->loadByUsername($username);
/** @var MagentoBackendModelAuthSession $session */
$session = $this->_objectManager->get('MagentoBackendModelAuthSession');
$session->setUser($user);
$session->processLogin();
if ($session->isLoggedIn())
$cookieManager = $this->_objectManager->get('MagentoFrameworkStdlibCookieManagerInterface');
$cookieValue = $session->getSessionId();
if ($cookieValue)
$sessionConfig = $this->_objectManager->get('MagentoBackendModelSessionAdminConfig');
$cookiePath = str_replace('autologin.php', 'index.php', $sessionConfig->getCookiePath());
$cookieMetadata = $this->_objectManager->get('MagentoFrameworkStdlibCookieCookieMetadataFactory')
->createPublicCookieMetadata()
->setDuration(3600)
->setPath($cookiePath)
->setDomain($sessionConfig->getCookieDomain())
->setSecure($sessionConfig->getCookieSecure())
->setHttpOnly($sessionConfig->getCookieHttpOnly());
$cookieManager->setPublicCookie($sessionConfig->getName(), $cookieValue, $cookieMetadata);
/** @var MagentoSecurityModelAdminSessionsManager $adminSessionManager */
$adminSessionManager = $this->_objectManager->get('MagentoSecurityModelAdminSessionsManager');
$adminSessionManager->processLogin();
/** @var MagentoBackendModelUrlInterface $backendUrl */
$backendUrl = $this->_objectManager->get('MagentoBackendModelUrlInterface');
$path = $backendUrl->getStartupPageUrl();
$url = $backendUrl->getUrl($path);
$url = str_replace('autologin.php', 'index.php', $url);
header('Location: '.$url);
exit;
return $this->_response;
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('TestApp');
$bootstrap->run($app);
Thanks ! It works ! However, in magento 2.3.1 an instance of the classMagentoBackendModelSessionAdminConfig
must be used insetPublicCookie
to get the correct session name. Otherwise, the cookie is named PHPSESSID and the redirect will prompt the admin panel login page
– user79886
May 31 at 11:59
if its works for you then click on the tick mark to help other people as well and also upvote as well. thanks
– Asad Khan
May 31 at 12:02
Yeah, just waiting for the edit to get accepted so it works for others as well. Thanks !
– user79886
May 31 at 12:07
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
user79886 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276861%2fhow-to-programmatically-login-an-admin-user%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is what i managed to do (based on How to perform auto-login in Magento2 admin?) and is working
?php
require __DIR__ . '/app/bootstrap.php';
class TestApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
$this->_eventManager = $this->_objectManager->get('MagentoFrameworkEventManager');
$this->_areaList = $this->_objectManager->get('MagentoFrameworkAppAreaList');
$this->_request = $this->_objectManager->get('MagentoFrameworkAppRequestHttp');
$this->_response = $this->_objectManager->get('MagentoFrameworkAppResponseHttp');
$this->_configLoader = $this->_objectManager->get('MagentoFrameworkObjectManagerConfigLoaderInterface');
$this->_state = $this->_objectManager->get('MagentoFrameworkAppState');
$this->_filesystem = $this->_objectManager->get('MagentoFrameworkFilesystem');
$this->registry = $this->_objectManager->get('MagentoFrameworkRegistry');
parent::__construct($objectManager, $this->_eventManager, $this->_areaList, $this->_request, $this->_response, $this->_configLoader, $this->_state, $this->_filesystem, $this->registry);
public function launch()
$areaCode = 'adminhtml';
$username = 'superadmin3';
$this->_state->setAreaCode($areaCode);
$this->_request->setPathInfo('/admin');
$this->_objectManager->configure($this->_configLoader->load($areaCode));
/** @var MagentoUserModelUser $user */
$user = $this->_objectManager->get('MagentoUserModelUser')->loadByUsername($username);
/** @var MagentoBackendModelAuthSession $session */
$session = $this->_objectManager->get('MagentoBackendModelAuthSession');
$session->setUser($user);
$session->processLogin();
if ($session->isLoggedIn())
$cookieManager = $this->_objectManager->get('MagentoFrameworkStdlibCookieManagerInterface');
$cookieValue = $session->getSessionId();
if ($cookieValue)
$sessionConfig = $this->_objectManager->get('MagentoBackendModelSessionAdminConfig');
$cookiePath = str_replace('autologin.php', 'index.php', $sessionConfig->getCookiePath());
$cookieMetadata = $this->_objectManager->get('MagentoFrameworkStdlibCookieCookieMetadataFactory')
->createPublicCookieMetadata()
->setDuration(3600)
->setPath($cookiePath)
->setDomain($sessionConfig->getCookieDomain())
->setSecure($sessionConfig->getCookieSecure())
->setHttpOnly($sessionConfig->getCookieHttpOnly());
$cookieManager->setPublicCookie($sessionConfig->getName(), $cookieValue, $cookieMetadata);
/** @var MagentoSecurityModelAdminSessionsManager $adminSessionManager */
$adminSessionManager = $this->_objectManager->get('MagentoSecurityModelAdminSessionsManager');
$adminSessionManager->processLogin();
/** @var MagentoBackendModelUrlInterface $backendUrl */
$backendUrl = $this->_objectManager->get('MagentoBackendModelUrlInterface');
$path = $backendUrl->getStartupPageUrl();
$url = $backendUrl->getUrl($path);
$url = str_replace('autologin.php', 'index.php', $url);
header('Location: '.$url);
exit;
return $this->_response;
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('TestApp');
$bootstrap->run($app);
Thanks ! It works ! However, in magento 2.3.1 an instance of the classMagentoBackendModelSessionAdminConfig
must be used insetPublicCookie
to get the correct session name. Otherwise, the cookie is named PHPSESSID and the redirect will prompt the admin panel login page
– user79886
May 31 at 11:59
if its works for you then click on the tick mark to help other people as well and also upvote as well. thanks
– Asad Khan
May 31 at 12:02
Yeah, just waiting for the edit to get accepted so it works for others as well. Thanks !
– user79886
May 31 at 12:07
add a comment |
This is what i managed to do (based on How to perform auto-login in Magento2 admin?) and is working
?php
require __DIR__ . '/app/bootstrap.php';
class TestApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
$this->_eventManager = $this->_objectManager->get('MagentoFrameworkEventManager');
$this->_areaList = $this->_objectManager->get('MagentoFrameworkAppAreaList');
$this->_request = $this->_objectManager->get('MagentoFrameworkAppRequestHttp');
$this->_response = $this->_objectManager->get('MagentoFrameworkAppResponseHttp');
$this->_configLoader = $this->_objectManager->get('MagentoFrameworkObjectManagerConfigLoaderInterface');
$this->_state = $this->_objectManager->get('MagentoFrameworkAppState');
$this->_filesystem = $this->_objectManager->get('MagentoFrameworkFilesystem');
$this->registry = $this->_objectManager->get('MagentoFrameworkRegistry');
parent::__construct($objectManager, $this->_eventManager, $this->_areaList, $this->_request, $this->_response, $this->_configLoader, $this->_state, $this->_filesystem, $this->registry);
public function launch()
$areaCode = 'adminhtml';
$username = 'superadmin3';
$this->_state->setAreaCode($areaCode);
$this->_request->setPathInfo('/admin');
$this->_objectManager->configure($this->_configLoader->load($areaCode));
/** @var MagentoUserModelUser $user */
$user = $this->_objectManager->get('MagentoUserModelUser')->loadByUsername($username);
/** @var MagentoBackendModelAuthSession $session */
$session = $this->_objectManager->get('MagentoBackendModelAuthSession');
$session->setUser($user);
$session->processLogin();
if ($session->isLoggedIn())
$cookieManager = $this->_objectManager->get('MagentoFrameworkStdlibCookieManagerInterface');
$cookieValue = $session->getSessionId();
if ($cookieValue)
$sessionConfig = $this->_objectManager->get('MagentoBackendModelSessionAdminConfig');
$cookiePath = str_replace('autologin.php', 'index.php', $sessionConfig->getCookiePath());
$cookieMetadata = $this->_objectManager->get('MagentoFrameworkStdlibCookieCookieMetadataFactory')
->createPublicCookieMetadata()
->setDuration(3600)
->setPath($cookiePath)
->setDomain($sessionConfig->getCookieDomain())
->setSecure($sessionConfig->getCookieSecure())
->setHttpOnly($sessionConfig->getCookieHttpOnly());
$cookieManager->setPublicCookie($sessionConfig->getName(), $cookieValue, $cookieMetadata);
/** @var MagentoSecurityModelAdminSessionsManager $adminSessionManager */
$adminSessionManager = $this->_objectManager->get('MagentoSecurityModelAdminSessionsManager');
$adminSessionManager->processLogin();
/** @var MagentoBackendModelUrlInterface $backendUrl */
$backendUrl = $this->_objectManager->get('MagentoBackendModelUrlInterface');
$path = $backendUrl->getStartupPageUrl();
$url = $backendUrl->getUrl($path);
$url = str_replace('autologin.php', 'index.php', $url);
header('Location: '.$url);
exit;
return $this->_response;
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('TestApp');
$bootstrap->run($app);
Thanks ! It works ! However, in magento 2.3.1 an instance of the classMagentoBackendModelSessionAdminConfig
must be used insetPublicCookie
to get the correct session name. Otherwise, the cookie is named PHPSESSID and the redirect will prompt the admin panel login page
– user79886
May 31 at 11:59
if its works for you then click on the tick mark to help other people as well and also upvote as well. thanks
– Asad Khan
May 31 at 12:02
Yeah, just waiting for the edit to get accepted so it works for others as well. Thanks !
– user79886
May 31 at 12:07
add a comment |
This is what i managed to do (based on How to perform auto-login in Magento2 admin?) and is working
?php
require __DIR__ . '/app/bootstrap.php';
class TestApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
$this->_eventManager = $this->_objectManager->get('MagentoFrameworkEventManager');
$this->_areaList = $this->_objectManager->get('MagentoFrameworkAppAreaList');
$this->_request = $this->_objectManager->get('MagentoFrameworkAppRequestHttp');
$this->_response = $this->_objectManager->get('MagentoFrameworkAppResponseHttp');
$this->_configLoader = $this->_objectManager->get('MagentoFrameworkObjectManagerConfigLoaderInterface');
$this->_state = $this->_objectManager->get('MagentoFrameworkAppState');
$this->_filesystem = $this->_objectManager->get('MagentoFrameworkFilesystem');
$this->registry = $this->_objectManager->get('MagentoFrameworkRegistry');
parent::__construct($objectManager, $this->_eventManager, $this->_areaList, $this->_request, $this->_response, $this->_configLoader, $this->_state, $this->_filesystem, $this->registry);
public function launch()
$areaCode = 'adminhtml';
$username = 'superadmin3';
$this->_state->setAreaCode($areaCode);
$this->_request->setPathInfo('/admin');
$this->_objectManager->configure($this->_configLoader->load($areaCode));
/** @var MagentoUserModelUser $user */
$user = $this->_objectManager->get('MagentoUserModelUser')->loadByUsername($username);
/** @var MagentoBackendModelAuthSession $session */
$session = $this->_objectManager->get('MagentoBackendModelAuthSession');
$session->setUser($user);
$session->processLogin();
if ($session->isLoggedIn())
$cookieManager = $this->_objectManager->get('MagentoFrameworkStdlibCookieManagerInterface');
$cookieValue = $session->getSessionId();
if ($cookieValue)
$sessionConfig = $this->_objectManager->get('MagentoBackendModelSessionAdminConfig');
$cookiePath = str_replace('autologin.php', 'index.php', $sessionConfig->getCookiePath());
$cookieMetadata = $this->_objectManager->get('MagentoFrameworkStdlibCookieCookieMetadataFactory')
->createPublicCookieMetadata()
->setDuration(3600)
->setPath($cookiePath)
->setDomain($sessionConfig->getCookieDomain())
->setSecure($sessionConfig->getCookieSecure())
->setHttpOnly($sessionConfig->getCookieHttpOnly());
$cookieManager->setPublicCookie($sessionConfig->getName(), $cookieValue, $cookieMetadata);
/** @var MagentoSecurityModelAdminSessionsManager $adminSessionManager */
$adminSessionManager = $this->_objectManager->get('MagentoSecurityModelAdminSessionsManager');
$adminSessionManager->processLogin();
/** @var MagentoBackendModelUrlInterface $backendUrl */
$backendUrl = $this->_objectManager->get('MagentoBackendModelUrlInterface');
$path = $backendUrl->getStartupPageUrl();
$url = $backendUrl->getUrl($path);
$url = str_replace('autologin.php', 'index.php', $url);
header('Location: '.$url);
exit;
return $this->_response;
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('TestApp');
$bootstrap->run($app);
This is what i managed to do (based on How to perform auto-login in Magento2 admin?) and is working
?php
require __DIR__ . '/app/bootstrap.php';
class TestApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
$this->_eventManager = $this->_objectManager->get('MagentoFrameworkEventManager');
$this->_areaList = $this->_objectManager->get('MagentoFrameworkAppAreaList');
$this->_request = $this->_objectManager->get('MagentoFrameworkAppRequestHttp');
$this->_response = $this->_objectManager->get('MagentoFrameworkAppResponseHttp');
$this->_configLoader = $this->_objectManager->get('MagentoFrameworkObjectManagerConfigLoaderInterface');
$this->_state = $this->_objectManager->get('MagentoFrameworkAppState');
$this->_filesystem = $this->_objectManager->get('MagentoFrameworkFilesystem');
$this->registry = $this->_objectManager->get('MagentoFrameworkRegistry');
parent::__construct($objectManager, $this->_eventManager, $this->_areaList, $this->_request, $this->_response, $this->_configLoader, $this->_state, $this->_filesystem, $this->registry);
public function launch()
$areaCode = 'adminhtml';
$username = 'superadmin3';
$this->_state->setAreaCode($areaCode);
$this->_request->setPathInfo('/admin');
$this->_objectManager->configure($this->_configLoader->load($areaCode));
/** @var MagentoUserModelUser $user */
$user = $this->_objectManager->get('MagentoUserModelUser')->loadByUsername($username);
/** @var MagentoBackendModelAuthSession $session */
$session = $this->_objectManager->get('MagentoBackendModelAuthSession');
$session->setUser($user);
$session->processLogin();
if ($session->isLoggedIn())
$cookieManager = $this->_objectManager->get('MagentoFrameworkStdlibCookieManagerInterface');
$cookieValue = $session->getSessionId();
if ($cookieValue)
$sessionConfig = $this->_objectManager->get('MagentoBackendModelSessionAdminConfig');
$cookiePath = str_replace('autologin.php', 'index.php', $sessionConfig->getCookiePath());
$cookieMetadata = $this->_objectManager->get('MagentoFrameworkStdlibCookieCookieMetadataFactory')
->createPublicCookieMetadata()
->setDuration(3600)
->setPath($cookiePath)
->setDomain($sessionConfig->getCookieDomain())
->setSecure($sessionConfig->getCookieSecure())
->setHttpOnly($sessionConfig->getCookieHttpOnly());
$cookieManager->setPublicCookie($sessionConfig->getName(), $cookieValue, $cookieMetadata);
/** @var MagentoSecurityModelAdminSessionsManager $adminSessionManager */
$adminSessionManager = $this->_objectManager->get('MagentoSecurityModelAdminSessionsManager');
$adminSessionManager->processLogin();
/** @var MagentoBackendModelUrlInterface $backendUrl */
$backendUrl = $this->_objectManager->get('MagentoBackendModelUrlInterface');
$path = $backendUrl->getStartupPageUrl();
$url = $backendUrl->getUrl($path);
$url = str_replace('autologin.php', 'index.php', $url);
header('Location: '.$url);
exit;
return $this->_response;
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('TestApp');
$bootstrap->run($app);
edited May 31 at 12:51
user79886
52
52
answered May 31 at 11:43
Asad KhanAsad Khan
50814
50814
Thanks ! It works ! However, in magento 2.3.1 an instance of the classMagentoBackendModelSessionAdminConfig
must be used insetPublicCookie
to get the correct session name. Otherwise, the cookie is named PHPSESSID and the redirect will prompt the admin panel login page
– user79886
May 31 at 11:59
if its works for you then click on the tick mark to help other people as well and also upvote as well. thanks
– Asad Khan
May 31 at 12:02
Yeah, just waiting for the edit to get accepted so it works for others as well. Thanks !
– user79886
May 31 at 12:07
add a comment |
Thanks ! It works ! However, in magento 2.3.1 an instance of the classMagentoBackendModelSessionAdminConfig
must be used insetPublicCookie
to get the correct session name. Otherwise, the cookie is named PHPSESSID and the redirect will prompt the admin panel login page
– user79886
May 31 at 11:59
if its works for you then click on the tick mark to help other people as well and also upvote as well. thanks
– Asad Khan
May 31 at 12:02
Yeah, just waiting for the edit to get accepted so it works for others as well. Thanks !
– user79886
May 31 at 12:07
Thanks ! It works ! However, in magento 2.3.1 an instance of the class
MagentoBackendModelSessionAdminConfig
must be used in setPublicCookie
to get the correct session name. Otherwise, the cookie is named PHPSESSID and the redirect will prompt the admin panel login page– user79886
May 31 at 11:59
Thanks ! It works ! However, in magento 2.3.1 an instance of the class
MagentoBackendModelSessionAdminConfig
must be used in setPublicCookie
to get the correct session name. Otherwise, the cookie is named PHPSESSID and the redirect will prompt the admin panel login page– user79886
May 31 at 11:59
if its works for you then click on the tick mark to help other people as well and also upvote as well. thanks
– Asad Khan
May 31 at 12:02
if its works for you then click on the tick mark to help other people as well and also upvote as well. thanks
– Asad Khan
May 31 at 12:02
Yeah, just waiting for the edit to get accepted so it works for others as well. Thanks !
– user79886
May 31 at 12:07
Yeah, just waiting for the edit to get accepted so it works for others as well. Thanks !
– user79886
May 31 at 12:07
add a comment |
user79886 is a new contributor. Be nice, and check out our Code of Conduct.
user79886 is a new contributor. Be nice, and check out our Code of Conduct.
user79886 is a new contributor. Be nice, and check out our Code of Conduct.
user79886 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276861%2fhow-to-programmatically-login-an-admin-user%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
want to login in admin panel programmaticlly?
– Asad Khan
May 31 at 11:35
yes, I am trying to automatically log into the admin panel
– user79886
May 31 at 11:40