{"id":37009260,"url":"https://github.com/ibra4/api-key","last_synced_at":"2026-01-14T00:52:49.749Z","repository":{"id":228852245,"uuid":"775097229","full_name":"ibra4/api-key","owner":"ibra4","description":"Laravel package provides a simple API key authentication mechanism for your Laravel applications. It allows you to protect your API endpoints by validating API keys sent with each request","archived":false,"fork":false,"pushed_at":"2024-06-24T02:49:07.000Z","size":11,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-13T10:58:06.338Z","etag":null,"topics":["api-key","authentication","laravel","php"],"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/ibra4.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}},"created_at":"2024-03-20T18:53:24.000Z","updated_at":"2025-03-10T09:20:02.000Z","dependencies_parsed_at":"2024-03-26T01:29:21.940Z","dependency_job_id":null,"html_url":"https://github.com/ibra4/api-key","commit_stats":null,"previous_names":["ibra4/api-key"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/ibra4/api-key","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibra4%2Fapi-key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibra4%2Fapi-key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibra4%2Fapi-key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibra4%2Fapi-key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibra4","download_url":"https://codeload.github.com/ibra4/api-key/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibra4%2Fapi-key/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-key","authentication","laravel","php"],"created_at":"2026-01-14T00:52:49.169Z","updated_at":"2026-01-14T00:52:49.741Z","avatar_url":"https://github.com/ibra4.png","language":"PHP","readme":"[![StandWithPalestineBadge](https://raw.githubusercontent.com/saedyousef/StandWithPalestine/main/badges/flat/IStandWithPalestine.svg)](https://techforpalestine.org/learn-more)\n\n# Laravel API Key Authentication Package\n\nThis Laravel package provides a simple API key authentication mechanism for your Laravel applications. It allows you to protect your API endpoints by validating API keys sent with each request.\n\n## Requirements\n\n- PHP 7.3 or higher\n\nTested on Laravel ^8.75\n\n## Installation\n\nYou can install this package via Composer:\n\n```bash\ncomposer require ibra4/api-key\n```\n\nNext, you should publish the package's configuration file:\n\n```bash\nphp artisan vendor:publish --tag=api_key\n```\n\nThen run migrations\n```bash\nphp artisan migrate\n```\n\nThis command will publish the `api_key.php` configuration file to your `config` directory.\n\n## Configuration\n\nAfter publishing the configuration file, you can modify the settings in `config/api_key.php` to fit your application's requirements. This file allows you to define various aspects of API key authentication, such as key length, expiration duration, etc.\n\n## Usage\n\n### Prepare your model\n\n- Implement `HasApiKeyInterface` interface\n- Use `HasApiKey` trait\n  ```patch\n  \u003c?php \n\n  + use Ibra\\ApiKey\\Interfaces\\HasApiKeyInterface;\n  + use Ibra\\ApiKey\\Traits\\HasApiKey;\n  - class User extends Authenticatable {\n  + class User extends Authenticatable implements HasApiKeyInterface {\n  +    use HasApiKey;\n  \n  }\n  ```\n\n### Generating API Keys\n\nTo generate an API key, you can use the provided artisan command:\n\n```bash\nphp artisan api_key:generate ibra 1\n```\n\nThis command will generate a new API key and associate it with a App\\Models\\User model with id 1.\n\nArguments\n\n- client_id: client's name\n- id: Model id\n- model \u003ci\u003e(optional)\u003c/i\u003e: Model class name (default: App\\Models\\User)\n- description \u003ci\u003e(optional)\u003c/i\u003e: Description\n\n### Protecting Routes\n\nTo protect your API routes with API key authentication, you can use the `simple_api_key` middleware provided by this package. Simply apply this middleware to the routes you want to protect:\n\n```php\nRoute::middleware('simple_api_key')-\u003eget('/api/resource', 'ResourceController@index');\n```\n\nThis middleware will verify the API key sent with each request and authenticate the associated user.\n\n### Deactivating API Keys\n\nYou can deactivate an API key using the provided artisan command:\n\n```bash\nphp artisan api-key:deactivate {client_id}\n```\n\nReplace `{client_id}` with the API key you want to deactivate.\n\n### Removing API Keys\n\nTo remove an API key from the system, you can use the following artisan command:\n\n```bash\nphp artisan api-key:remove {client_id}\n```\n\nReplace `{client_id}` with the API key you want to remove.\n\n### Listing API Keys\n\nYou can list all API keys stored in the database using the following artisan command:\n\n```bash\nphp artisan api-key:list\n```\n\nThis command will display a list of all API keys along with their associated user and status, like.\n\n\u003ctable\u003e\n    \u003cthead\u003e\n        \u003ctr\u003e\n            \u003cth\u003eclient_id\u003c/th\u003e\n            \u003cth\u003edescription\u003c/th\u003e\n            \u003cth\u003emodel\u003c/th\u003e\n            \u003cth\u003emodel_id\u003c/th\u003e\n            \u003cth\u003ekey\u003c/th\u003e\n            \u003cth\u003eis_active\u003c/th\u003e\n            \u003cth\u003eexpires_at\u003c/th\u003e\n            \u003cth\u003ecreated_at\u003c/th\u003e\n        \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n        \u003ctr\u003e\n            \u003ctd\u003eibrahim\u003c/td\u003e\n            \u003ctd\u003eHello World\u003c/td\u003e\n            \u003ctd\u003eApp\\Models\\User\u003c/td\u003e\n            \u003ctd\u003e2\u003c/td\u003e\n            \u003ctd\u003e6af97902bfb6f1c15fea8e079babeca731ee9fb04dd08bb7b6efb80baaed1eb6\u003c/td\u003e\n            \u003ctd\u003e1\u003c/td\u003e\n            \u003ctd\u003e2024-04-19T18:25:58.000000Z\u003c/td\u003e\n            \u003ctd\u003e2024-03-20T18:25:58.000000Z\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003elara\u003c/td\u003e\n            \u003ctd\u003e\u003c/td\u003e\n            \u003ctd\u003eApp\\Models\\Client\u003c/td\u003e\n            \u003ctd\u003e1\u003c/td\u003e\n            \u003ctd\u003edaabe8a2ed4b84f2156a12dca5b29d8aa4b8fbf4b27813aac077bdc654f57c7b\u003c/td\u003e\n            \u003ctd\u003e0\u003c/td\u003e\n            \u003ctd\u003e2024-04-19T18:33:15.000000Z\u003c/td\u003e\n            \u003ctd\u003e2024-03-20T18:33:15.000000Z\u003c/td\u003e\n        \u003c/tr\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n\n## Middleware Logic\n\nThe `ApiKeyMiddleware` included in this package is responsible for authenticating API requests based on the provided API key. It checks the validity and status of the API key and logs in the associated user if the key is valid and active.\n\n## Contributing\n\nContributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on GitHub.\n\n## License\n\nThis package is open-source software licensed under the [MIT license](LICENSE.md).\n\n## Credits\n\nThis package is developed and maintained by [Ibrahim Hammad](https://github.com/ibra4).\n\n---\n\nFeel free to add any additional sections or customize the content as per your project's requirements. This README provides a basic overview of the package and its usage.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibra4%2Fapi-key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibra4%2Fapi-key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibra4%2Fapi-key/lists"}