{"id":22546366,"url":"https://github.com/danilowa/laravel-api-auth","last_synced_at":"2026-02-27T03:01:51.068Z","repository":{"id":257791188,"uuid":"861519631","full_name":"DaniloWA/laravel-api-auth","owner":"DaniloWA","description":"A simple and configurable Laravel package for easy API authentication with standardized responses.","archived":false,"fork":false,"pushed_at":"2025-05-04T08:09:02.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-28T16:50:32.399Z","etag":null,"topics":["api","auth","authentication","danilo","danilowa","laravel","laravel-api","laravel-api-auth","laravel-auth","oliveira","package"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DaniloWA.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-09-23T03:59:27.000Z","updated_at":"2025-05-04T08:08:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"2cf9acbb-4c05-4298-8090-8a623c82729d","html_url":"https://github.com/DaniloWA/laravel-api-auth","commit_stats":null,"previous_names":["danilowa/laravel-api-auth"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/DaniloWA/laravel-api-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaniloWA%2Flaravel-api-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaniloWA%2Flaravel-api-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaniloWA%2Flaravel-api-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaniloWA%2Flaravel-api-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DaniloWA","download_url":"https://codeload.github.com/DaniloWA/laravel-api-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaniloWA%2Flaravel-api-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29883111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T23:51:21.483Z","status":"online","status_checked_at":"2026-02-27T02:00:06.759Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","auth","authentication","danilo","danilowa","laravel","laravel-api","laravel-api-auth","laravel-auth","oliveira","package"],"created_at":"2024-12-07T15:07:25.803Z","updated_at":"2026-02-27T03:01:51.052Z","avatar_url":"https://github.com/DaniloWA.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cstrong\u003eStreamline API Authentication with Laravel API Auth!\u003c/strong\u003e This simple and configurable package provides an easy solution for managing API authentication in Laravel applications using Laravel Sanctum. It includes features for user registration, login, logout, and retrieving current user data, all with standardized JSON responses.\n\u003c/p\u003e\n\n## Index\n\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [API Endpoints](#api-endpoints)\n- [Usage Examples](#usage-examples)\n- [Documentation](#documentation)\n- [Contributing](#contributing)\n- [License](#license)\n- [Contact](#contact)\n\n## Features\n\n- **Seamless User Authentication:** Easily manage user authentication using Laravel Sanctum.\n- **Standardized JSON Responses:** Consistent response structure for all API interactions, simplifying error handling and data management.\n- **Flexible Configuration:** Customize response formats and API settings according to your application's needs.\n\n## Requirements\n\nEnsure your project meets the following requirements before using this package:\n\n- **Laravel Framework:** Version 9.0 or higher.\n- **PHP:** Version 8.0 or higher.\n- **Composer:** PHP dependency manager.\n\n## Installation\n\nTo integrate the Laravel API Auth into your Laravel project, follow these steps:\n\n1. **Install via Composer:**\n\nRun the following command in your terminal:\n\n```bash\ncomposer require danilowa/laravel-api-auth\n```\n\n2. **Publish the Configuration (Optional):**\n\nAfter installation, publish the configuration file:\n\n```bash\nphp artisan vendor:publish --provider=\"Danilowa\\LaravelApiAuth\\Providers\\ApiAuthServiceProvider\"\n```\n\nThis will create a configuration file at `config/apiauth.php`, where you can customize the package settings.\n\n## Configuration\n\nThe package configuration can be found in the `config/apiauth.php` file. This file allows you to customize various aspects of the API authentication system according to your project's needs.\n\n### Key Configurations:\n\n1. **Route Prefix:**\n\n   - **`route_prefix`:** Allows you to define a custom prefix for all authentication routes. By default, it's set to `auth`. You can customize this via the `API_AUTH_ROUTE_PREFIX` environment variable, making it easy to change to `v1/auth`, for example.\n\n2. **User Model Configuration:**\n\n   - **`user_model`:** Specify the class name of the user model that will be used for authentication. The default is `App\\Models\\User::class`. If you have a custom user model, change this value accordingly.\n\n3. **Token Settings:**\n\n   - **`default_token_name`:** Defines the default name for the access tokens generated during registration or login. You can use a different name for each token if desired.\n\n4. **Token Revocation Strategy:**\n\n   - **`revoke_all_tokens`:** A boolean value that determines whether all tokens for a user should be revoked upon logout. If set to `true`, all tokens will be revoked; if `false`, only the current token will be revoked.\n\n5. **Customizable Messages:**\n\n   - **`messages`:** Allows you to customize the messages returned during the authentication process. For example, you can modify messages like \"User created successfully!\" to fit your communication style.\n\n6. **Validation Rules:**\n\n   - **`validation`:** Defines the validation rules for login and registration requests. You can adjust these rules to meet your application's policies, including format requirements for email or password strength.\n\n### Configuration Example\n\n```php\nreturn [\n    'route_prefix' =\u003e env('API_AUTH_ROUTE_PREFIX', 'auth'),\n    'user_model' =\u003e 'App\\Models\\User::class',\n    'default_token_name' =\u003e 'default_token',\n    'revoke_all_tokens' =\u003e true,\n    'messages' =\u003e [\n        'user_created' =\u003e 'User created successfully!',\n        'user_logged_in' =\u003e 'User logged in!',\n        'credentials_incorrect' =\u003e 'The provided credentials are incorrect.',\n        'tokens_revoked' =\u003e 'Tokens revoked successfully!',\n        'default_error' =\u003e 'An error occurred.',\n    ],\n    'validation' =\u003e [\n        'login' =\u003e [\n            'rules' =\u003e [\n                'email' =\u003e 'required|email',\n                'password' =\u003e 'required|string',\n            ],\n        ],\n        'registration' =\u003e [\n            'rules' =\u003e [\n                'name' =\u003e 'required|string|max:255',\n                'email' =\u003e 'required|email|unique:users',\n                'password' =\u003e 'required|string|min:8',\n                'token_name' =\u003e 'nullable|string',\n            ],\n        ],\n    ],\n];\n```\n\n## API Endpoints\n\nThis package provides the following API endpoints for user authentication:\n\n- **POST /auth/register**: Register a new user.\n- **POST /auth/login**: Log in an existing user.\n- **POST /auth/logout**: Log out the authenticated user.\n- **GET /auth/user**: Retrieve the current authenticated user's information.\n\n## Usage Examples\n\n### Register User\n\nTo register a new user, send a POST request to `/auth/register` with the following JSON body:\n\n```json\n{\n  \"name\": \"John Doe\",\n  \"email\": \"john.doe@example.com\",\n  \"password\": \"password123\"\n}\n```\n\n### Login User\n\nTo log in, send a POST request to `/auth/login`:\n\n```json\n{\n  \"email\": \"john.doe@example.com\",\n  \"password\": \"password123\"\n}\n```\n\n### Logout User\n\nTo log out the authenticated user, send a POST request to `/auth/logout`.\n\n### Retrieve Current User\n\nTo retrieve the current user's data, send a GET request to `/auth/user` with the appropriate authentication token.\n\n## Documentation\n\n### API Endpoints\n\n#### Register\n\n- **Description:** This endpoint allows a new user to register for the application by providing their name, email, and password.\n- **Example Request:**\n\n```http\nPOST /auth/register\nContent-Type: application/json\n\n{\n  \"name\": \"John Doe\",\n  \"email\": \"john.doe@example.com\",\n  \"password\": \"password123\"\n}\n```\n\n- **Example Response:**\n\n```json\n{\n  \"status\": \"success\",\n  \"message\": \"User registered successfully.\",\n  \"data\": {\n    \"user\": {\n      \"id\": 1,\n      \"name\": \"John Doe\",\n      \"email\": \"john.doe@example.com\"\n    }\n  }\n}\n```\n\n#### Login\n\n- **Description:** This endpoint allows an existing user to log in by providing their email and password.\n- **Example Request:**\n\n```http\nPOST /auth/login\nContent-Type: application/json\n\n{\n  \"email\": \"john.doe@example.com\",\n  \"password\": \"password123\"\n}\n```\n\n- **Example Response:**\n\n```json\n{\n  \"status\": \"success\",\n  \"message\": \"User logged in successfully.\",\n  \"data\": {\n    \"token\": \"your_jwt_token_here\"\n  }\n}\n```\n\n#### Logout\n\n- **Description:** This endpoint allows the authenticated user to log out of the application.\n- **Example Request:**\n\n```http\nPOST /auth/logout\nAuthorization: Bearer your_jwt_token_here\n```\n\n- **Example Response:**\n\n```json\n{\n  \"status\": \"success\",\n  \"message\": \"User logged out successfully.\"\n}\n```\n\n#### Current User\n\n- **Description:** This endpoint retrieves the current authenticated user's information.\n- **Example Request:**\n\n```http\nGET /auth/user\nAuthorization: Bearer your_jwt_token_here\n```\n\n- **Example Response:**\n\n```json\n{\n  \"status\": \"success\",\n  \"message\": \"User data retrieved successfully.\",\n  \"data\": {\n    \"id\": 1,\n    \"name\": \"John Doe\",\n    \"email\": \"john.doe@example.com\"\n  }\n}\n```\n\n## Contributing\n\nYou can contribute by forking the repository and submitting a pull request.\n\n## License\n\nThis package is licensed under the MIT License.\n\n## Contact\n\nFor any questions or feedback, please reach out to:\n\n- **Danilo Oliveira:** daniloworkdev@gmail.com\n- **Website:** [daniloo.dev](http://www.daniloo.dev)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilowa%2Flaravel-api-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanilowa%2Flaravel-api-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilowa%2Flaravel-api-auth/lists"}