yireo / magento2-admin-auto-login
Development-only Magento 2 module that automatically logs in a configured admin user (developer mode, env.php flag and IP allowlist required)
Package info
github.com/yireo/Yireo_AdminAutoLogin
Type:magento2-module
pkg:composer/yireo/magento2-admin-auto-login
Requires
- php: >=8.2 <8.6
- magento/framework: ^101.0|^102.0|^103.0
- magento/module-backend: ^101.0|^102.0
- magento/module-security: ^100.4
- magento/module-user: ^101.0
- psr/log: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- loki/magento2-functional-tests: @dev
- phpunit/phpunit: ^10.5
- yireo/magento2-integration-test-helper: ~0.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Automatically login a specified user without any JavaScript trick or weird redirect, but simply by spoofing the login mechanism
Warning
This module logs anybody who can reach the Magento Admin Panel in as the configured admin user. It is meant for local development only. Never install it on a production or publicly reachable environment.
Installation
Install this module as a development dependency only:
composer require --dev yireo/magento2-admin-auto-login bin/magento module:enable Yireo_AdminAutoLogin bin/magento setup:upgrade
Usage
Add the following to your app/etc/env.php:
'yireo_admin_autologin' => [ 'enabled' => true, 'username' => 'exampleAdmin', // Optional, defaults to localhost and private network ranges 'allowed_ips' => ['127.0.0.1', '::1', '172.16.0.0/12'], ],
The auto-login only happens when all of the following conditions are met:
- Magento runs in developer mode (
bin/magento deploy:mode:set developer); enabledis set to the booleantrueinapp/etc/env.php;- The client IP matches one of the
allowed_ips(single IPs or CIDR ranges, as array or comma-separated string). Whenallowed_ipsis not set,127.0.0.0/8,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16andfc00::/7are allowed. An empty array blocks all IPs. The client IP is always theREMOTE_ADDRof the request: proxy headers likeX-Forwarded-Forare ignored, because any client can send them; - The configured admin user exists, is active and is not locked.
The login follows the regular Magento login flow: the session ID is regenerated, the admin session is registered by
Magento_Security and the event backend_auth_user_login_success is dispatched. Every auto-login is logged as a
warning in var/log/system.log.
Notes:
- Two-Factor Authentication (
Magento_TwoFactorAuth) still applies, when enabled; - The login and logout pages are skipped. After logging out, the next Admin Panel page logs you in again;
- When secret keys in URLs are enabled, the first page after auto-login redirects to the Admin startup page.
Upgrading from 1.0
The setting system/admin/autologin_username in the database (core_config_data) is no longer used, because a
database setting can be copied to other environments by accident. Move the username to app/etc/env.php (see above)
and remove the old setting:
bin/magento config:delete system/admin/autologin_username