nizam/passport-api

Automates Laravel Passport setup for API authentication in Laravel 8 and higher, with ready-to-use routes and controllers. Similar to Laravel Breeze API.

V1.0.0 2024-08-14 18:51 UTC

This package is auto-updated.

Last update: 2025-02-20 21:23:23 UTC


README

Nizam Passport API is a Laravel package designed to streamline API authentication setup using Laravel Passport. Compatible with Laravel versions 8, 9, 10, and 11, this package simplifies Passport integration by automating the installation and configuration process, making it ideal for API-only projects.

Features

  • Automatic Laravel Passport Installation: Ensures Passport is installed and configured. πŸš€
  • API Authentication Scaffolding: Provides necessary controllers, requests, and routes. πŸ› οΈ
  • Configuration Updates: Automatically updates api.php, web.php, and appends to auth.php to use Passport. πŸ”§
  • User Model Update: Adds the HasApiTokens trait to the User model. πŸ‘€
  • Environment Configuration: Updates .env with default settings. 🌐
  • Auth Configuration Update: Adds the API guard to the auth.php configuration file with the Passport driver if it’s not already present. This ensures your application uses Passport's TokenGuard for authenticating incoming API requests. πŸ›‘οΈ
  • Cleanup: Removes unnecessary files and directories for API-only applications. πŸ—‘οΈ

Requirements

  • PHP: ^7.3|^8.0
  • Laravel: ^8.0|^9.0|^10.0|^11.0
  • Laravel Passport: ^10.0|^11.0|^12.0

Installation

  1. Install the Nizam Passport API package:

    composer require nizam/passport-api
  2. Set up the Passport API:

    php artisan nizam:install-passport-api

    This command will:

    • Check and install Laravel Passport if necessary
    • Set up required controllers, requests, and routes
    • Add the HasApiTokens trait to the User model
    • Update your auth.php configuration to use Passport as the API driver
    • Update your web.php and api.php configurations
    • Modify .env with default URL settings
    • Clean up unnecessary files and directories

Usage

This package provides the following API routes:

  • POST /api/auth/register: Register a new user πŸ“

  • POST /api/auth/login: Log in a user πŸ”‘

  • POST /api/auth/logout: Log out a user (requires authentication) πŸšͺ

  • POST /api/auth/forgot-password: Send a password reset link πŸ“§

  • POST /api/auth/reset-password: Reset the user's password πŸ”„

  • GET /api/auth/verify-email/{id}/{hash}: Verify email address (requires authentication) βœ”οΈ

  • POST /api/auth/email/verification-notification: Resend email verification notification (requires authentication) πŸ”„

  • GET /api/auth/user: Get authenticated user information (requires authentication) πŸ§‘β€πŸ’»

Configuration

After installation, ensure your application's config/auth.php configuration file includes an API authentication guard with the Passport driver. This configuration instructs your application to use Passport's TokenGuard for authenticating incoming API requests.

Examples

To see how the integration and setup have evolved, you can view the differences between versions in the repository commits. For specific examples of changes, check out the commit history.

Reporting Issues

If you encounter any issues or have suggestions for improvements, please follow these steps to report them:

  1. Check Existing Issues: Before creating a new issue, check the Issues tab to see if the issue has already been reported.
  2. Create a New Issue: If the issue has not been reported, click on the "New Issue" button and provide a detailed description of the problem. Include:
    • A clear title
    • A detailed description of the issue
    • Steps to reproduce the issue
    • Any error messages or logs
    • The version of Laravel and Laravel Passport you are using
  3. Submit the Issue: Once you have provided all the necessary information, submit the issue. The maintainers will review and address it as soon as possible.

License

This package is licensed under the MIT License. See the LICENSE file for details.

Credits

  • Nizam Omer - Package author and maintainer

Acknowledgements

Thank you for using Nizam Passport API! Special thanks to My God, everyone who has contributed, tested, and provided feedback. Your support is greatly appreciated. May this package help you in your API development journey. πŸ™