ashokdubariya/module-login-as-customer
Composer 安装命令:
composer require ashokdubariya/module-login-as-customer
包简介
Secure admin-to-customer login with multi-website support and audit logging for Magento 2
关键字:
README 文档
README
This repository contains a Login as Customer module that allows authorized Admin users to log in as customers from the Admin Panel with multi-website support and full audit traceability.
Key Features
- Multi-Website Support - Login as customer on any website (Ashokdubariya, Coverion, etc.)
- Smart Button Detection - Automatically shows single button or dropdown based on available websites
- Grid & Edit Page Access - Login from customer grid or edit page
- Cryptographically Secure - Token-based authentication with SHA-256 hashing
- Complete Audit Trail - Track every login attempt with full details
- ACL Protected - Granular permission control
- One-Time Tokens - Prevents replay attacks
- Configurable Expiry - Default 5-minute token lifetime
Security Features
- Cryptographically Secure Tokens - Uses
random_bytes(32)for token generation - SHA-256 Hash Storage - Tokens stored as hashes, never plaintext
- Single-Use Tokens - Automatically invalidated after first use
- Configurable Expiry - Default 5 minutes, prevents stale tokens
- ACL Protected - Dual permissions for login action and audit access
- Complete Audit Trail - Logs every attempt with admin/customer/IP/timestamp
- CSRF Protection - Leverages Magento's form key validation
- No Password Access - Bypasses password, uses session-based login
- IP Tracking - Records admin IP for forensics
- Replay Prevention - Hash comparison prevents token reuse
Requirements
- Magento Open Source 2.4.4+
- PHP 8.1+
Module Information
- Module Name:
Ashokdubariya_LoginAsCustomer - Package Name:
ashokdubariya/module-login-as-customer - Module Type: Magento 2 Custom Module
- License: MIT
Installation
Method 1: Composer Installation (Recommended)
composer require ashokdubariya/module-login-as-customer php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento cache:flush
Method 2: Manual Installation
- Copy the module to Magento:
mkdir -p app/code/Ashokdubariya/LoginAsCustomer
# Copy module files to app/code/Ashokdubariya/LoginAsCustomer
- Run Magento commands:
php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento cache:flush
Configuration
Navigate to: Stores > Configuration > Ashokdubariya > Login as Customer
Settings
| Setting | Description | Default |
|---|---|---|
| Enable Module | Enable/Disable functionality | Yes |
| Token Lifetime (minutes) | How long token remains valid | 5 |
| Redirect Page After Login | URL path after login | customer/account |
| Enable Audit Logging | Log all attempts | Yes |
Permissions Setup
Grant Permissions to Admin Role
- Navigate to: System > Permissions > User Roles
- Edit the desired role
- Under Role Resources, expand Customers
- Check:
- Login as Customer > Perform Login as Customer Action
- Login as Customer > View Audit Log
- Under Stores > Configuration, check:
- Login as Customer Configuration
- Save Role
Usage Guide
Method 1: From Customer Grid (Quick Access)
Single Website Customer:
- Navigate to: Customers > All Customers
- Locate customer row
- Click Select in Actions dropdown
- Click Login as Customer
- New window opens with customer logged in
Multi-Website Customer:
- Navigate to: Customers > All Customers
- Locate customer row
- Click Select in Actions dropdown
- You'll see multiple options:
- Login as Customer (Default)
- Login as Customer (Wholesale)
- etc.
- Click the desired website option
- New window opens with customer logged into that website
Method 2: From Customer Edit Page
Single Website Customer:
- Navigate to: Customers > All Customers
- Click Edit on a customer
- Click Login as Customer button in header
- New window opens with customer logged in
Multi-Website Customer:
- Navigate to: Customers > All Customers
- Click Edit on a customer
- Click Login as Customer dropdown button in header
- Select the desired website from dropdown:
- Default
- Wholesale
- etc.
- New window opens with customer logged into selected website
Website Selection Logic
The module intelligently detects available websites:
- Global Customer Sharing (scope = 0): Shows all websites
- Per-Website Sharing (scope = 1): Shows only customer's assigned website
- Single Website: Simple button/action
- Multiple Websites: Dropdown button/multiple actions
Viewing Audit Log
- Navigate to: Customers > Login as Customer
- View grid with columns:
- Log ID
- Admin ID / Username
- Customer ID / Email
- IP Address
- Status (Pending/Success/Expired/Failed)
- Store View
- Created At / Expires At / Used At
- Use filters to search by admin, customer, status, date range
Security Considerations
What we do?
- Token Generation: Cryptographically secure
random_bytes(32)= 64 hex chars - Token Storage: Store SHA-256 hash only (64 chars), original token discarded after URL generation
- Single-Use: Token status changed from
pending→successafter first use, subsequent attempts rejected - Expiration: Configurable TTL (default 5 min), server-side timestamp validation
- Audit Logging: Every attempt logged with:
- Admin ID/username
- Customer ID/email
- IP address
- Timestamp
- Outcome (success/failed/expired)
- ACL Enforcement: Separate permissions for:
- Performing login action
- Viewing audit log
- Modifying configuration
- CSRF Protection: Magento's built-in form key validation on admin controllers
- Session Regeneration: Customer session ID regenerated after login
- No Password Exposure: Customer password hash never accessed
What we don't do?
- No customer password access
- No plaintext token storage
- No unlimited token lifetime
- No token reuse
- No bypass of ACL permissions
- No modification of customer data during login
Technical Details
- Detects customer's primary website ID
- Checks customer sharing configuration
- Retrieves all accessible websites
- Generates appropriate UI (single/multiple actions)
- Passes
website_idparameter to controller - Controller selects correct store based on website
- Redirects to appropriate website base URL
Support
- Source: GitHub Repository
- Issues: GitHub Issues
License
This project is licensed under the MIT License - see the LICENSE file for details.
ashokdubariya/module-login-as-customer 适用场景与选型建议
ashokdubariya/module-login-as-customer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「audit trail」 「magento2」 「Login as customer」 「multi-website」 「admin login」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ashokdubariya/module-login-as-customer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ashokdubariya/module-login-as-customer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ashokdubariya/module-login-as-customer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Log adding/updating/deleting of elements
Doctrine ORM provider for the auditor audit-log library.
Provide a way to secure accesses to all routes of an symfony application.
PB Web Media Audit Bundle for Symfony
It's a barebone security class written on PHP
Audit trail package for Laravel Eloquent
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-16