vm-engine / authman
Standalone authentication and account security for Laravel on Fortify and Flux: username or email login, lockout and IP blocking, email OTP, passkeys, password policy, two-factor refresh, profile and security screens
Requires
- php: ^8.3
- hosseinhezami/laravel-permission-manager: ^2.0
- laravel/fortify: ^1.41
- laravel/framework: ^13.0
- livewire/flux: ^2.20
- livewire/livewire: ^4.0
- maxmind-db/reader: ^1.12
- vm-engine/ui-kit: ^0.1 || ^0.2
- vm-engine/wire-util: ^0.1
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- orchestra/testbench: ^11.0
- pestphp/pest: ^5.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-05 22:48:30 UTC
README
Authentication and account security for Laravel apps built on Fortify and free Flux: login by email or username, account lockout and IP blocking, email one-time codes, passkeys, password expiry and forced changes, a second-factor refresh for remember-me sessions, and profile/security screens. Roles and permissions come from hosseinhezami/laravel-permission-manager.
authman owns the auth screens: it configures Fortify after every provider has booted, so the host's own FortifyServiceProvider needs no edits.
Requirements
- PHP 8.3+, Laravel 13, Livewire 4, Flux (free) 2.20+, Fortify 1.41+ (with laravel/passkeys)
vm-engine/ui-kit^0.1 andvm-engine/wire-util^0.1- Not spatie/laravel-permission: it uses the same
roles/permissionstables andhasRole()/assignRole()names as the permission manager.
Installation
composer require vm-engine/authman php artisan authman:install # asks before each change; --force applies all php artisan migrate php artisan authman:sync-permissions # also on every deploy php artisan authman:super-admin you@example.com php artisan authman:geoip-update # optional: countries (see "Country lookup") npm run build
authman:install, on a Livewire starter-kit app:
- Publishes
config/authman.php. - Adds
HasAuthman,PermissionTraitandimplements AuthmanUsertoApp\Models\User. It warns if Spatie'sHasRolesis there. - Removes the starter kit's
profile.editandsecurity.editroutes fromroutes/settings.php. authman serves both under the same names and paths (settings/profile,settings/security). - Adds
<flux:toast />and<x-ui::confirm-dialog />before@fluxScriptsin your layouts, and<x-authman::impersonation-banner />in the app layouts. - Imports the ui-kit and authman stylesheets in
resources/css/app.css, so Tailwind sees their classes. - Adds
<x-authman::admin-nav />after the firstflux:sidebar.groupinresources/views/layouts/app/sidebar.blade.php. - Adds
SoftDeletestoApp\Models\User, for the user trash.
Passkey screens load config('authman.passkeys.vite_entry') (default resources/js/passkeys.js, shipped by the starter kit, from npm @laravel/passkeys).
Configuration
| Key | Default | |
|---|---|---|
layouts.guest / layouts.app |
layouts::auth / layouts::app |
Host layouts for guest and signed-in screens |
username.enabled |
true |
Log in with email or username |
lockout.max_attempts / minutes |
5 / 15 | Account lock after wrong passwords |
lockout.ip_max_attempts / ip_minutes |
20 / 60 | IP block after failures across all accounts |
password.expiry_days |
null |
Global expiry (users.password_expiry_days overrides) |
email_otp.* |
on, ['super-admin'], 10 min, 60 s resend, 5 tries |
Email one-time codes |
two_factor.refresh_hours / super_admin_refresh_hours |
null |
Re-check remember-me sessions |
otp_protect.remember_minutes |
15 | How long a verify-identity check lasts |
recaptcha.* |
off | reCAPTCHA v2 on login and registration (AUTHMAN_RECAPTCHA, RECAPTCHA_SITE_KEY, RECAPTCHA_SECRET_KEY) |
avatar.* |
public disk, 2048 KB, 1024 px |
Profile pictures |
nav.items |
the five access admin links | The sidebar menu: links, or a package nav group (['component' => 'webms::admin-sidebar']). Add one with php artisan authman:add-menu webms::admin-sidebar |
profile.extra_links |
Appearance | Extra links in the settings navigation |
routes.* |
web, settings/profile, settings/security |
Middleware and profile paths |
routes.admin_prefix / admin_middleware |
admin/auth / web, auth, verified |
Where the access admin lives |
user_fields / user_sections |
none | Extra user data (see below) |
registration.role / fields_view |
null / null |
Role slug given to every new user (registering fails if it does not exist), and a host view for the register-only fields |
invitations.expiry_hours |
48 | How long an invitation link works |
impersonation.blocked_routes |
credential and admin pages | Pages that refuse while signed in as someone else |
audit.models / audit.except |
none / secrets and timestamps | Models recorded in the activity log, and columns never recorded |
audit.max_value_length |
1000 | Longer recorded values are cut |
audit.retention_days |
365 | Activity log and sign-in attempts; null keeps them |
geoip.* |
Cloudflare header off, MaxMind file in storage/app/authman |
Country lookup (below) |
routes.activity_path |
settings/activity |
The signed-in user's own activity page |
permissions |
Access, WebMS, File manager | The permission catalog (below) |
Behaviour worth knowing
- One login field. It is named
login, and authman setsfortify.usernametologin. Password reset still usesemail. - No account enumeration. An unknown login and a wrong password get the same message. Unknown logins lock out exactly like real ones. "Inactive" is only said after a correct password.
- Failures that never count toward lockout: inactive accounts, i.e. any failure where the password was right.
- Email codes apply to users who enabled them or hold a role in
email_otp.required_roles, unless they use an authenticator app. Passkey logins skip both. - Forced and expired passwords redirect every request to
/password/changeuntil changed. JSON requests get 403. - Sensitive actions.
- On routes, use the
authman.otpmiddleware (orauthman.otp:5for a 5-minute window). - In Livewire actions, use
WithOtpProtectionandif (! $this->ensureOtpVerified()) { return; }.
- On routes, use the
- Unlocking:
php artisan authman:unblock --ip=1.2.3.4or--user=email|username|id. A password reset also lifts an account lock. - Passkeys are listed and removed by delete token, never by id.
- Events for an audit log to subscribe to:
UserLoggedIn,LoginFailed,UserLocked,IpBlocked,PasswordChanged,ProfileUpdated,EmailChanged,UserCreated,UserUpdated,UserDeleted($permanent),ImpersonationStarted,ImpersonationStopped,RoleCreated,RoleUpdated,RoleDeleted,UserRolesChanged,UserPermissionsChanged.UserUpdatedandProfileUpdatedcarry$changes. - Cache settings authman changes:
cache.serializable_classesgetsIlluminate\Support\Collectionadded. The permission manager caches permission lists as a Collection. Laravel 13 doesn't unserialize objects by default, so without this entry every cache hit on a database, file or Redis store comes back broken. A host value oftrue, or no value at all, already allows every class and is left unchanged.fortify.limiters.loginis switched off, because authman's account lock and IP block replace it.
Access admin
<x-authman::admin-nav /> (added to the starter-kit sidebar by authman:install) links the screens the signed-in user may open, under authman.routes.admin_prefix (default /admin/auth, route names authman.admin.*, middleware authman.routes.admin_middleware + can:authman.access):
| Screen | Permission |
|---|---|
| Users: list, create, edit | authman.users.read / create / update |
| Users: delete and restore; delete permanently | authman.users.delete; authman.users.force_delete plus a fresh identity check |
| Users: per-user permissions | authman.users.permissions |
| Users: sign in as a user | authman.users.impersonate |
| Roles: list, create, edit, delete | authman.roles.read / create / update / delete |
| Sign-in attempts | authman.security.read |
| Blocked access: unblock IPs, unlock accounts | authman.security.read; acting needs authman.security.update |
| Activity log | authman.activity.read |
Roles get an allow-only permission matrix and an optional "inherits from" role (its permissions show as locked cells). System roles (is_system, or the super-admin slug) can't be edited or deleted; roles still given to users, or inherited by other roles, can't be deleted. Deletes and unblocks go by delete token, never by id.
Permission catalog
The role screen lists the abilities in config('authman.permissions'): group name => abilities, as a list or ability => label. "webms.page.publish.update" shows as resource "Page Publish", action "Update". authman's own group (Access) is included, and so are WebMS and the file manager when they're installed; they only check Laravel Gate abilities and know nothing about authman. Add your own:
'permissions' => [ // ...authman's defaults... 'Shop' => ['shop.orders.read', 'shop.orders.refund' => 'Refund orders'], ],
Then run php artisan authman:sync-permissions (and on every deploy). It writes the catalog to the permission manager; --prune removes permissions it created that you no longer declare, and never touches system permissions or ones created another way. Your code keeps calling Gate, can(), @can and can: middleware as usual.
Users
- Creating a user: send an invitation (the default) or set a temporary password they must change at their next sign-in. An invitation is a single-use link that expires after
invitations.expiry_hours; only a hash of it is stored, and resending voids the old link. Accepting it sets the password, verifies the email address and signs the user in. - Guards, checked inside every action (super admins pass every Gate check, so a policy wouldn't stop them):
- only super admins edit, delete or change the permissions of a super admin or of anyone who can open the access admin (
authman.access), so no admin can take over a stronger one; and only super admins give or remove thesuper-adminrole - changing roles needs
authman.roles.updateas well - nobody deletes or deactivates themselves or the last active super admin, and nobody changes their own permissions
- only super admins edit, delete or change the permissions of a super admin or of anyone who can open the access admin (
- Delete moves the user to the trash and renames their email and username (
deleted_x7k2ab_ada@example.test,ada_deleted_x7k2ab) so both can be reused at once. It also signs them out everywhere and removes their passkeys. Restore puts the originals back, unless someone took them meanwhile. - Permanent delete works on trashed users, needs a fresh identity check, and is refused while another table still points at the user through a foreign key that would block the delete. The message lists them as
table.column. WithoutSoftDeleteson your user model there's no trash, and delete is permanent straight away. - Your own code: once
authman:installaddsSoftDeletes, a plain$user->delete()(the starter kit's "delete account" form, for example) only trashes the user, without freeing their email. CallforceDelete()where you mean a real delete. - Per-user permissions allow or deny single abilities on top of the user's roles, optionally until a date. A user's deny always wins. They're stored in the permission manager's
user_permissions, socan()reads them.
Extending user data
Your user table and model are yours: add columns with your own migrations. To show, validate and save them on authman's screens, declare them in config/authman.php:
'user_fields' => [ 'phone' => ['label' => 'Phone', 'type' => 'text', 'rules' => ['nullable', 'string', 'max:30'], 'on' => ['admin', 'profile']], 'department' => ['type' => 'select', 'options' => ['it' => 'IT', 'hr' => 'HR'], 'rules' => ['nullable', 'in:it,hr'], 'list' => true], ],
Types: text, textarea, email, number, select, multi-select (cast the column to array), date, switch. on picks the admin user form, the profile page and/or the register form (default: admin only). list adds a column and filter to the user list.
Registration fields. A field with 'register' in on is validated with its rules and saved onto the new user when someone registers. The register page renders them as plain inputs (it is not a Livewire page, so the wire:model form of the admin and profile screens does not apply), with old() values kept after an error. To render them yourself, set authman.registration.fields_view to a view name: it replaces the plain inputs and must post the same field names. To give every new user a role, set authman.registration.role to its slug; the role must exist, and the user model must use the permission manager's PermissionTrait.
Labels and select option labels go through __() when authman reads them, so a JSON translation of 'Phone' is picked up even though config files cannot translate. A column cast to a backed enum works with select fields.
For anything a column can't hold, add a section class:
use Illuminate\Contracts\Auth\Authenticatable; use VmEngine\Authman\Contracts\UserFormSection; final class AddressSection implements UserFormSection { public function view(): string { return 'users.address-section'; } // inputs bind wire:model="extra.street" public function rules(?Authenticatable $user): array { return ['street' => ['nullable', 'string', 'max:120']]; } public function fill(?Authenticatable $user): array { return ['street' => (string) $user?->address?->street]; } public function save(Authenticatable $user, array $data): void { $user->address()->updateOrCreate([], ['street' => $data['street'] ?? null]); } }
Register it in user_sections (AddressSection::class for the admin form, or AddressSection::class => ['admin', 'profile']). save() runs inside the transaction that saves the user, so if it throws, nothing is saved. Section keys share one extra namespace.
Impersonation
Holders of authman.users.impersonate can sign in as another user from the user list. Never as a super admin, an inactive user or themselves; and only super admins can sign in as someone who can impersonate too.
- A banner (
<x-authman::impersonation-banner />) shows who you are signed in as, with Stop to switch back. - Meanwhile the pages in
impersonation.blocked_routes(profile, security, password change, the admin screens…) answer 403, and Livewire actions from them are refused too. - Switching never fires Laravel's
Loginevent, so it isn't recorded as their sign-in; listen forImpersonationStarted/ImpersonationStoppedinstead. - Logging out while impersonating ends the whole session, without touching the user's remember-me token.
Activity log
authman records, in the activities table:
- its own events: sign-in security (password, email, profile, lockouts, IP blocks), users (created, updated, trashed, deleted, roles, per-user permissions), roles (created, updated with the permissions added and removed, deleted) and impersonation;
- changes to the models you list in
authman.audit.models:Invoice::class => ['except' => ['internal_notes']], or justInvoice::class. Created, updated (only the changed columns), deleted and restored are recorded. The globalaudit.exceptcolumns and a model's$hiddenattributes are never recorded; - your own entries:
Audit::record('shop.refund', $order, ['amount' => 25], 'Refunded an order'). A description may be a lang key. In console code, name the actor:Audit::record(..., actor: $user).
Good to know:
- Who: while someone is signed in as another user, the entry shows "Admin (as Ada)". Console and queue work show "System", without an IP address.
- When: entries are written after the surrounding transaction commits, so a rolled-back change leaves no trace.
- Not recorded: sign-ins (see Sign-in attempts), and model changes made with
saveQuietly(),withoutEvents()or a massquery()->update(). - At rest: the before/after values are encrypted with
APP_KEY; when rotating the key, setAPP_PREVIOUS_KEYS. - Screens: the admin log (filters, a details dialog,
authman.activity.read), a "Recent activity" panel on the user page, and Settings → Activity for everyone: their own sign-ins and actions. The last one is closed while someone is signed in as them. - Retention:
audit.retention_days(default 365,nullkeeps everything) prunes the log and sign-in attempts. authman schedulesmodel:prunedaily, so the host must run the scheduler (schedule:run).
Country lookup
Sign-in attempts and activity entries carry a country. Either:
- set
AUTHMAN_MAXMIND_ACCOUNT_IDandAUTHMAN_MAXMIND_LICENSE_KEY(a free GeoLite2 account) and runphp artisan authman:geoip-update; it is scheduled weekly from then on, and keeps the current file if a download fails, or - set
AUTHMAN_GEOIP_CLOUDFLARE=truewhen the app sits behind Cloudflare, to trust itsCF-IPCountryheader.
Private and reserved addresses have no country. To use another provider, bind your own VmEngine\Authman\Contracts\CountryDatabase.
Testing the package
cd packages/authman
composer install
vendor/bin/phpstan analyse --memory-limit=1G
vendor/bin/pint
vendor/bin/pest
Licence
MIT.