Download the PHP package andmarruda/authmodule without Composer
On this page you can find all versions of the php package andmarruda/authmodule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andmarruda/authmodule
More information about andmarruda/authmodule
Files in andmarruda/authmodule
Package authmodule
Short Description Invitation-based authentication module for Laravel
License
Informations about the package authmodule
AuthModule
A self-contained Laravel module for invitation-based user registration with audit logging. Built with Clean Architecture (Ports & Adapters), making it easy to swap implementations without touching business logic.
Features
- Invitation workflow -- managers invite users by email, users register via secure token
- Role-based access -- only managers can create invitations
- Audit logging -- every action (invite, accept, register) is logged with IP, user agent, and metadata
- Queued emails -- invitation emails are dispatched to the queue for async delivery
- Secure tokens -- 64-character hex tokens generated with
random_bytes() - Idempotent acceptance -- accepting an already-accepted invitation safely returns success
- Resource scoping -- optional
resource_scopefield for multi-tenant or permission scenarios - Native teams -- users can belong to multiple teams and teams can contain multiple users
- Hybrid auth ready -- session (
web) remains default, optionalsanctumguard can be enabled per route group - JWT auth ready -- native
jwtguard with bearer token issuance endpoint (/auth/jwt/token)
Architecture
Requirements
- PHP 8.1+
- Laravel 11+
- A configured mail driver (for sending invitations)
- A configured queue worker (invitations use
Mail::queue()) - Depends on
andmarruda/authorization-module(Authorizable/HasAuthorization)
Installation
1. Install via Composer
2. Register the service provider
For Laravel 11+, the provider is auto-discovered via Composer.
If auto-discovery is disabled in your app, add the provider manually in bootstrap/providers.php:
The service provider automatically:
- Binds all interfaces to their Eloquent/Mail implementations
- Loads routes, migrations, and views
3. Run migrations
This creates module tables such as invitations, teams, team_user, team_invitations, auth_audit_logs, otps, and user_preferences, plus updates users when needed.
Note: The module ships its own
userstable migration. If your project already has one, remove or adjust the module's2026_02_15_100000_create_users_table.phpmigration to avoid conflicts. Upgrade note: If you already applied an olderteam_invitationsmigration withinvited_by, run the package upgrade migration (2026_02_20_101100_migrate_team_invitations_to_morphable_inviter.php) to migrate toinviter_type/inviter_idand remove the legacy column.
4. Configure the invitation URL
Invitation emails include a link pointing to your frontend. Set the base URL in your .env:
The generated link format is: {FRONTEND_URL}/invitations/accept?token={TOKEN}
Falls back to APP_URL if FRONTEND_URL is not set.
5. Configure mail and queue
Make sure your mail driver and queue worker are properly configured so invitation emails are sent:
Usage
API Endpoints
| Method | URI | Description | Auth |
|---|---|---|---|
POST |
/invitations/create |
Create an invitation | Yes (manager only) |
POST |
/invitations/accept |
Accept an invitation | No |
POST |
/users/register |
Register via invitation token | No |
POST |
/auth/jwt/token |
Issue JWT token from email/password | No |
POST |
/teams |
Create a new team | Yes |
GET |
/teams/mine |
List current user teams | Yes |
POST |
/teams/invitations/create |
Invite user to team | Yes |
GET |
/teams/invitations/resolve?token=... |
Resolve invitation and detect account existence | No |
POST |
/teams/invitations/redeem |
Redeem invitation (existing user path) | Optional auth |
POST |
/teams/invitations/register |
Register from team invitation (new user path) | No |
GET |
/auth/social/{provider}/redirect |
Start OAuth login (google, github) |
No |
GET |
/auth/social/{provider}/callback |
OAuth callback | No |
GET |
/auth/social/profile/status |
Get missing profile fields after social auth | Yes |
POST |
/auth/social/profile/complete |
Complete missing profile data | Yes |
Create an invitation (manager only)
Responses:
201-- Invitation created, email queued403-- Authenticated user is not a manager422-- Validation error or email already registered
Accept an invitation
Responses:
200-- Invitation accepted (idempotent)404-- Token not found410-- Invitation expired
Register a new user
Responses:
201-- User created404-- Token not found410-- Invitation expired or already used
Typical flow
Social login (Google/GitHub)
This package supports google and github with Laravel Socialite.
-
Add provider credentials to your
.env: -
Configure
config/services.phpin your Laravel app: - (Optional) publish and tune package config:
config/authmodule.php lets you customize allowed providers, scopes, and post-login/error redirects.
For onboarding after social login, configure:
authmodule.profile.required_user_fieldsauthmodule.profile.required_preference_keysauthmodule.profile.redirect_to_onboarding
-
Manual test flow:
- (Optional) Protect app routes until profile is complete:
Creating a manager
The first manager must be created manually (via tinker, a seeder, or a direct DB update):
From there, managers can invite other users through the API.
Customization
Session + Sanctum
The package supports web (session) and sanctum (API token) at the same time.
Publish config and set guards per route group:
By default, protected endpoints accept both session (web) and API token (sanctum) authentication.
If you enable sanctum guards, install/configure Sanctum in the host app.
When creating team invitations, send inviter_type (user/tenant) and inviter_id if you want a non-user inviter context.
The default authorizer only allows the authenticated user to be the inviter; provide your own authorizer class to validate tenant contexts.
JWT (native)
You can also use the built-in jwt guard for bearer authentication.
Default algorithm is RS256 (recommended for multi-client/mobile/public API scenarios).
EdDSA (Ed25519) is also supported when libsodium is available.
Configuration keys:
Minimal .env for RS256:
For EdDSA, set AUTHMODULE_JWT_ALGORITHM=EdDSA and provide base64 keys:
Token endpoint:
Generate EdDSA keys + ready-to-use env file:
Useful options:
The command creates:
eddsa-private.key.b64eddsa-public.key.b64- env variables for
AUTHMODULE_JWT_ALGORITHM,AUTHMODULE_JWT_PRIVATE_KEY,AUTHMODULE_JWT_PUBLIC_KEY,AUTHMODULE_JWT_KEY_ID, andAUTHMODULE_JWT_TTL_MINUTES.
If ext-sodium is not available, the command exits with guidance to install/enable it.
Swapping implementations
The module uses interface bindings, so you can replace any implementation. Override the bindings in your own service provider:
Available interfaces:
| Interface | Default Implementation | Purpose |
|---|---|---|
UserRepositoryInterface |
EloquentUserRepository |
User persistence |
InvitationRepositoryInterface |
EloquentInvitationRepository |
Invitation persistence |
TokenGeneratorInterface |
SecureTokenGenerator |
Token generation |
AuditLoggerInterface |
EloquentAuditLogger |
Audit logging |
InvitationMailerInterface |
MailInvitationMailer |
Sending invitation emails |
Publishing views
To customize the invitation email template, copy the view to your project's resources:
Laravel will automatically use the vendor override.
Testing
The module includes both unit and feature tests.
Running tests
Test coverage
Unit tests (mocked dependencies):
RegisterUserTest-- registration with valid/invalid/expired/used tokensInviteUserTest-- manager permissions, duplicate email checks, resource scopingAcceptInvitationTest-- acceptance, expiration, idempotency
Feature tests (full HTTP with database):
UserControllerTest-- registration endpoint, validation, audit log creationInvitationControllerTest-- invitation creation, acceptance, mail dispatch, auth guards
Using factories in your own tests
Database schema
users
| Column | Type | Notes |
|---|---|---|
id |
bigint | PK |
name |
string | |
email |
string | unique |
password |
string | hashed |
is_manager |
boolean | default false |
email_verified_at |
timestamp | nullable |
remember_token |
string | nullable |
created_at / updated_at |
timestamps |
invitations
| Column | Type | Notes |
|---|---|---|
id |
bigint | PK |
email |
string | indexed with accepted_at |
token |
string(64) | unique |
invited_by |
FK -> users | cascade on delete |
resource_scope |
string | nullable |
expires_at |
timestamp | default: 7 days from creation |
accepted_at |
timestamp | nullable |
created_at / updated_at |
timestamps |
auth_audit_logs
| Column | Type | Notes |
|---|---|---|
id |
bigint | PK |
action |
string | invitation_created, invitation_accepted, user_registered |
actor_id |
FK -> users | nullable, null on delete |
actor_email |
string | nullable |
target_email |
string | nullable |
invitation_id |
FK -> invitations | nullable, null on delete |
resource_scope |
string | nullable |
metadata |
json | nullable |
ip_address |
string | nullable |
user_agent |
text | nullable |
created_at |
timestamp |
teams
| Column | Type | Notes |
|---|---|---|
id |
bigint | PK |
name |
string | |
slug |
string | unique |
owner_id |
FK -> users | cascade on delete |
created_at / updated_at |
timestamps |
team_user
| Column | Type | Notes |
|---|---|---|
id |
bigint | PK |
team_id |
FK -> teams | cascade on delete |
user_id |
FK -> users | cascade on delete |
role |
string | default member |
joined_at |
timestamp | nullable |
created_at / updated_at |
timestamps |
team_invitations
| Column | Type | Notes |
|---|---|---|
id |
bigint | PK |
team_id |
FK -> teams | cascade on delete |
email |
string | indexed with accepted_at |
token |
string(64) | unique |
inviter_type |
string | morph type (User, Tenant, etc.) |
inviter_id |
bigint | morph id |
role |
string | default member |
expires_at |
timestamp | |
accepted_at |
timestamp | nullable |
created_at / updated_at |
timestamps |
License
This module is part of the Novos Horizontes project.
All versions of authmodule with dependencies
ext-openssl Version *
andmarruda/authorization-module Version >=0.0.1
illuminate/auth Version >=10.0
illuminate/mail Version >=10.0
illuminate/database Version >=10.0
illuminate/routing Version >=10.0
illuminate/support Version >=10.0
illuminate/queue Version >=10.0
laravel/socialite Version ^5.18