Search by

vm-engine / authman

adods

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

Package info

github.com/vm-engine/authman

pkg:composer/vm-engine/authman

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.0 2026-12-04 02:51 UTC

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 and vm-engine/wire-util ^0.1
  • Not spatie/laravel-permission: it uses the same roles/permissions tables and hasRole()/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:

  1. Publishes config/authman.php.
  2. Adds HasAuthman, PermissionTrait and implements AuthmanUser to App\Models\User. It warns if Spatie's HasRoles is there.
  3. Removes the starter kit's profile.edit and security.edit routes from routes/settings.php. authman serves both under the same names and paths (settings/profile, settings/security).
  4. Adds <flux:toast /> and <x-ui::confirm-dialog /> before @fluxScripts in your layouts, and <x-authman::impersonation-banner /> in the app layouts.
  5. Imports the ui-kit and authman stylesheets in resources/css/app.css, so Tailwind sees their classes.
  6. Adds <x-authman::admin-nav /> after the first flux:sidebar.group in resources/views/layouts/app/sidebar.blade.php.
  7. Adds SoftDeletes to App\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 sets fortify.username to login. Password reset still uses email.
  • 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/change until changed. JSON requests get 403.
  • Sensitive actions.
    • On routes, use the authman.otp middleware (or authman.otp:5 for a 5-minute window).
    • In Livewire actions, use WithOtpProtection and if (! $this->ensureOtpVerified()) { return; }.
  • Unlocking: php artisan authman:unblock --ip=1.2.3.4 or --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. UserUpdated and ProfileUpdated carry $changes.
  • Cache settings authman changes:
    • cache.serializable_classes gets Illuminate\Support\Collection added. 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 of true, or no value at all, already allows every class and is left unchanged.
    • fortify.limiters.login is 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 the super-admin role
    • changing roles needs authman.roles.update as well
    • nobody deletes or deactivates themselves or the last active super admin, and nobody changes their own permissions
  • 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. Without SoftDeletes on your user model there's no trash, and delete is permanent straight away.
  • Your own code: once authman:install adds SoftDeletes, a plain $user->delete() (the starter kit's "delete account" form, for example) only trashes the user, without freeing their email. Call forceDelete() 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, so can() 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 Login event, so it isn't recorded as their sign-in; listen for ImpersonationStarted / ImpersonationStopped instead.
  • 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 just Invoice::class. Created, updated (only the changed columns), deleted and restored are recorded. The global audit.except columns and a model's $hidden attributes 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 mass query()->update().
  • At rest: the before/after values are encrypted with APP_KEY; when rotating the key, set APP_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, null keeps everything) prunes the log and sign-in attempts. authman schedules model:prune daily, 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_ID and AUTHMAN_MAXMIND_LICENSE_KEY (a free GeoLite2 account) and run php 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=true when the app sits behind Cloudflare, to trust its CF-IPCountry header.

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.