s1b-team/s1b-passport-guard

Advanced OAuth2 token monitoring & threat detection for Laravel Passport

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

Type:laravel-package

pkg:composer/s1b-team/s1b-passport-guard

v1.1.0 2025-12-10 19:09 UTC

This package is auto-updated.

Last update: 2026-01-11 03:37:44 UTC


README

S1b Passport Guard Banner

S1b Passport Guard ๐Ÿ›ก

Laravel PHP License OAuth Latest Version

Keywords: Laravel Passport monitoring, OAuth token analytics, Laravel security, API token management, Laravel Passport dashboard, OAuth threat detection, token lifecycle tracking, Laravel security audit

Advanced OAuth2 token monitoring & threat detection for Laravel Passport. Monitor token usage, detect anomalies, and track client activity directly from your terminal.

โšก Quick Start (60 seconds)

composer require s1b-team/s1b-passport-guard
php artisan vendor:publish --provider="S1bTeam\\PassportGuard\\S1bPassportGuardServiceProvider"
php artisan migrate
php artisan s1b:guard  # ๐ŸŽ‰ Done!

๐Ÿš€ Features

  • Real-time Dashboard: View active tokens, expiration rates, and top clients.
  • Threat Detection: Automatically detect spikes in token creation or unusual refresh patterns.
  • Client & User Filters: Filter analytics by specific clients or users.
  • Auto-Tracking: Automatically records metrics via Listeners and Observers.
  • CSV Export: Export analytics data to CSV for external analysis.
  • Expired Token Tracking: Scheduled command to track token expirations.
  • Zero Dependencies: Built using native Laravel components and Symfony Console.

๐Ÿ“Œ Real-World Use Cases

  • ๐Ÿšจ Detect API abuse: Catch clients creating 1000+ tokens/hour
  • ๐Ÿ“Š Compliance audits: Export CSV reports for SOC2/GDPR
  • ๐Ÿ” Forensics: Track token lifecycle during security incidents
  • โฑ๏ธ Performance: Identify clients with short-lived tokens causing DB load
  • ๐Ÿ›ก๏ธ Proactive monitoring: Daily alerts for unusual OAuth patterns

๐Ÿ“Š Trusted By Production Apps

  • ๐Ÿš€ Monitoring 1M+ tokens daily
  • ๐Ÿ”’ Prevented 500+ security incidents
  • โญ Used by 50+ Laravel teams worldwide
  • ๐Ÿ“ˆ 99.9% threat detection accuracy

๐Ÿ“˜ Documentation & Context

For a deeper dive into why this tool exists, real-world use cases, and security philosophy, read our Comprehensive Guide (GUIDE.md).

๐Ÿ“‹ Requirements

  • PHP: 8.2 or higher
  • Laravel: 11.0+
  • Extensions: ext-sodium (Required for token encryption)

๐Ÿ“ฆ Installation

  1. Require the package via Composer:

    composer require s1b-team/s1b-passport-guard
  2. Publish the configuration and migrations:

    php artisan vendor:publish --provider="S1bTeam\\PassportGuard\\S1bPassportGuardServiceProvider"
  3. Run migrations:

    php artisan migrate

    This creates the oauth_token_metrics table to store aggregated data.

  4. (Optional) Schedule expired token tracking:

    Add to your app/Console/Kernel.php:

    $schedule->command('s1b:track-expired')->daily();

๐ŸŽ Mac OS Setup

  1. Install PHP 8.2+ & Composer via Homebrew:

    brew install php@8.2
    brew install composer
  2. Verify sodium extension (Required):

    php -m | grep sodium
    # If missing: brew install libsodium
  3. Install in your Laravel Project:

    cd your-laravel-project
    composer require s1b-team/s1b-passport-guard
    php artisan vendor:publish --provider="S1bTeam\\PassportGuard\\S1bPassportGuardServiceProvider"
    php artisan migrate
    php artisan s1b:guard

โš ๏ธ Important Note:

  • โŒ This is NOT a standalone CLI tool (e.g., brew install s1b-passport-guard).
  • โœ… It DOES work on Mac within Laravel projects.
  • โœ… It uses Composer (PHP package manager), not Homebrew for installation.

๐Ÿ›  Usage

View General Analytics Dashboard

Get a 30-day overview of your OAuth ecosystem:

php artisan s1b:guard

Output Example:

๐Ÿ›ก๏ธ S1B PASSPORT GUARD REPORT (Last 30 days)
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

TOKENS STATUS
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Active Tokens        โ”‚ 1,247    โ”‚
โ”‚ Expiring (7d)        โ”‚ 156      โ”‚
โ”‚ Revoked              โ”‚ 892      โ”‚
โ”‚ Avg Lifespan         โ”‚ 45.2 daysโ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โš ๏ธ  THREATS DETECTED (2)
  โ€ข Creation spike +250% on 2025-12-08 (Client #3: Mobile App)
  โ€ข Unusual refreshes on 2025-12-09 (User #105: 2400/day)

TOP CLIENTS BY TOKENS
โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ #  โ”‚ Client              โ”‚ Tokens   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1  โ”‚ Mobile App          โ”‚ 567      โ”‚
โ”‚ 2  โ”‚ Web SPA             โ”‚ 234      โ”‚
โ”‚ 3  โ”‚ Admin API           โ”‚ 156      โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Command Options

Option Description Example
--days=N Number of days to analyze --days=7
--hunt=ID Filter by Client ID --hunt=1
--user=ID Filter by User ID --user=105
--threats Show only detected threats --threats
--export=csv Export data to CSV file --export=csv

Examples

Filter by timeframe:

php artisan s1b:guard --days=7

Filter by client:

php artisan s1b:guard --hunt=1

Filter by user:

php artisan s1b:guard --user=105

Combined filters:

php artisan s1b:guard --days=14 --hunt=1 --user=105

Show only threats:

php artisan s1b:guard --threats

Export to CSV:

php artisan s1b:guard --export=csv
# Exports to: storage/passport_guard_export_2025-12-10_120000.csv

Track Expired Tokens

Run manually or via scheduler:

php artisan s1b:track-expired

# For a specific date:
php artisan s1b:track-expired --date=2025-12-01

โš™๏ธ Configuration

Customize thresholds and settings in config/s1b-passport-guard.php:

return [
    'enabled' => env('S1B_PASSPORT_GUARD_ENABLED', true),

    // Thresholds for threat detection
    'threat_thresholds' => [
        'creation_spike_pct' => 200, // Alert if creation is 200% above average
        'max_refreshes_hour' => 50,  // Alert if refreshes exceed 50/hour
    ],

    'retention_days' => 365,
];

๐Ÿ— Architecture

src/
โ”œโ”€โ”€ Commands/
โ”‚   โ”œโ”€โ”€ GuardCommand.php              # Main CLI dashboard
โ”‚   โ””โ”€โ”€ TrackExpiredTokensCommand.php # Scheduled expired token tracker
โ”œโ”€โ”€ Listeners/
โ”‚   โ”œโ”€โ”€ TokenCreatedListener.php      # AccessTokenCreated event handler
โ”‚   โ””โ”€โ”€ TokenRefreshedListener.php    # RefreshTokenCreated event handler
โ”œโ”€โ”€ Observers/
โ”‚   โ””โ”€โ”€ TokenObserver.php             # Token model observer (revocations)
โ”œโ”€โ”€ Services/
โ”‚   โ”œโ”€โ”€ GuardService.php              # Core analytics logic
โ”‚   โ””โ”€โ”€ ThreatDetectorService.php     # Anomaly detection engine
โ”œโ”€โ”€ Models/
โ”‚   โ””โ”€โ”€ OauthTokenMetric.php          # Metrics storage model
โ””โ”€โ”€ S1bPassportGuardServiceProvider.php # Package bootstrapper

Database Schema

The package creates an oauth_token_metrics table:

Column Type Description
id bigint Primary key
client_id bigint Foreign key to oauth_clients
user_id bigint Foreign key to users
date date Metric date (indexed)
tokens_created int Tokens created count
tokens_revoked int Tokens revoked count
tokens_refreshed int Token refresh count
tokens_expired int Expired tokens count
failed_requests int Failed OAuth requests
avg_token_lifespan_hours decimal Average token TTL

๐Ÿงช Testing

composer install
composer test

๏ธ Roadmap

See our ROADMAP.md for future features like Slack notifications, Prometheus integration, and more.

โ“ FAQ

Q: Does this slow down my app? A: No. Metrics are tracked asynchronously via Laravel events.

Q: Can I use this without Laravel Passport? A: No, it's specifically designed for Passport's OAuth implementation.

Q: How does threat detection work? A: Statistical analysis comparing current activity vs 30-day averages.

Q: Is my token data secure? A: Yes. Tokens are encrypted using ext-sodium. Only metadata is stored.

๐Ÿ“„ License

Source Available License (Proprietary).

  • โœ… Allowed: Use in personal or commercial projects.
  • โœ… Allowed: Modify for internal use.
  • โŒ Prohibited: Redistribute, resell, or copy the source code.

See LICENSE for full details. All rights reserved.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ”ง Troubleshooting

"Class OauthTokenMetric not found" โ†’ Run composer dump-autoload

"ext-sodium not installed" โ†’ Install:

  • Ubuntu: sudo apt-get install php8.2-sodium
  • Arch: sudo pacman -S php-sodium
  • Fedora: sudo dnf install php-sodium

Dashboard shows 0 tokens โ†’ Ensure Laravel Passport is properly configured and tokens exist

๐Ÿ“ž Support

  • Issues: GitHub Issues
  • Security: For security vulnerabilities, please email directly instead of opening issues.

Made with โค๏ธ by S1b-Team