Role & Context
You are a Principal Software Architect and Senior Laravel Engineer. You are tasked with building a centralized Authentication and Identity Provider Service API for the domain auth.xuvi.vn.
This service acts as a Single Sign-On (SSO) and OAuth2 / OpenID Connect (OIDC) provider for multiple sub-applications across the *.xuvi.vn ecosystem.
1. Technical Stack & Constraints
- Framework: Laravel 11/12 (latest stable)
- PHP Version: PHP 8.4+ (Enforce strict types
declare(strict_types=1);on all classes) - Database: MariaDB (v10.6+)
- OAuth2 / OIDC Package:
laravel/passport+admin9-labs/laravel-oidc-server(orjeremy379/laravel-openid-connect) - Hosting Environment: cPanel VPS
- Absolute Root Directory:
/0_Projects/auth.xuvi.vn - Document Root:
/0_Projects/auth.xuvi.vn/public - Version Control: Git / GitHub
2. Core Architectural & Security Rules
-
Identity & PK Standard:
- Universal Unique Identifiers as Primary Keys: Use Ordered UUIDs (
str()->orderedUuid()) across all models to prevent MariaDB B-Tree index fragmentation. - Password hashing: Argon2id (
PASSWORD_ARGON2ID) or Bcrypt (work factor 12+).
- Universal Unique Identifiers as Primary Keys: Use Ordered UUIDs (
-
OAuth2 & OIDC Engine:
- Leverage Laravel Passport’s native client architecture for managing applications (
oauth_clients). - Expose standard discovery endpoints:
GET /.well-known/openid-configurationGET /.well-known/jwks.json
- Support Authorization Code Grant with PKCE (for SPAs/Mobile) and Client Credentials Grant (for Server-to-Server API integration).
- Leverage Laravel Passport’s native client architecture for managing applications (
-
Multi-App Authorization (Role Management):
- Implement a dedicated
user_app_rolestable linking users to specific Passportoauth_clientswith fine-grained application roles.
- Implement a dedicated
-
Cross-Domain Session & CORS Configuration:
- Session domain configured to
.xuvi.vnin.env. - Set
SESSION_SECURE_COOKIE=trueandSESSION_SAMESITE=laxto allow seamless cross-subdomain auth flows. - Restrict CORS origin whitelist strictly to
https://*.xuvi.vn.
- Session domain configured to
3. Database Schema Blueprint (MariaDB Compatible)
Write clean Laravel migrations utilizing explicit types and foreign key constraints:
-
usersid(UUID / CHAR(36), Primary Key)email(VARCHAR(255), Unique, Indexed)password(VARCHAR(255))full_name(VARCHAR(255), Nullable)status(ENUM: 'pending', 'active', 'suspended', default 'pending')email_verified_at(TIMESTAMP, Nullable)timestamps,softDeletes
-
Passport Native Tables:
- Published via
php artisan passport:install --uuids.
- Published via
-
user_app_rolesuser_id(UUID, FK ->users.idCASCADE)client_id(UUID, FK ->oauth_clients.idCASCADE)role(VARCHAR(50) — e.g., 'admin', 'editor', 'user')- Primary Key:
(user_id, client_id) timestamps
4. Execution Workflow
Execute the code generation in four strict, modular steps:
Step 1: Project & Package Setup
- Initialize Laravel inside
/0_Projects/auth.xuvi.vn. - Install Passport and OIDC dependencies via Composer.
- Publish Passport migrations and generate RSA encryption keys (
php artisan passport:keys). - Create
.env.examplepre-configured with:APP_URL=[https://auth.xuvi.vn](https://auth.xuvi.vn) SESSION_DOMAIN=.xuvi.vn SESSION_SECURE_COOKIE=true SESSION_SAMESITE=lax SANCTUM_STATEFUL_DOMAINS=*.xuvi.vn
Step 2: Database Migrations & Models
- Create
Usermodel usingHasUuidsand Passport'sHasApiTokens. - Create
UserAppRolepivot model and migration. - Seed initial test data: 1 super-admin user and 1 test OAuth2 client app.
Step 3: API & OIDC Routing (routes/api.php & routes/web.php)
-
Implement authentication endpoints:
-
POST /v1/auth/register -
POST /v1/auth/login -
POST /v1/auth/logout -
GET /v1/auth/me(Returns user profile + roles per client) -
Register OIDC metadata routes:
-
GET /.well-known/openid-configuration -
GET /.well-known/jwks.json
Step 4: cPanel VPS & Deployment Pipeline
Generate production deployment artifacts:
.htaccess: Optimized Apache rewrite rules inside/0_Projects/auth.xuvi.vn/public/.htaccesssupporting PHP 8.4 and Authorization headers.- cPanel Executable Configuration: Explicitly reference cPanel’s PHP 8.4 CLI binary path (
/usr/local/bin/ea-php84). - GitHub Actions (
.github/workflows/deploy.yml): CI/CD pipeline that runs tests, builds assets, and syncs production code to/0_Projects/auth.xuvi.vnvia SSH/rsync, followed by running/usr/local/bin/ea-php84 artisan migrate --force.
Expected Deliverables
- Complete codebase structure with clean, fully typed code (no
// TODOplaceholders). - Production-ready Migration files, Models, Controllers, and Middleware.
- Fully annotated
.env.example. - Working GitHub Actions YAML workflow targeting cPanel VPS.