{"id":18255243,"url":"https://github.com/mxl/laravel-api-key","last_synced_at":"2025-04-04T17:31:07.045Z","repository":{"id":57022506,"uuid":"255370642","full_name":"mxl/laravel-api-key","owner":"mxl","description":"API key authorization for Laravel with replay attack prevention","archived":false,"fork":false,"pushed_at":"2020-07-24T15:39:27.000Z","size":8,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T07:54:05.774Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mxl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-13T15:45:42.000Z","updated_at":"2022-12-11T23:14:29.000Z","dependencies_parsed_at":"2022-08-23T13:51:00.044Z","dependency_job_id":null,"html_url":"https://github.com/mxl/laravel-api-key","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxl%2Flaravel-api-key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxl%2Flaravel-api-key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxl%2Flaravel-api-key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxl%2Flaravel-api-key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mxl","download_url":"https://codeload.github.com/mxl/laravel-api-key/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223150661,"owners_count":17095959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-05T10:15:13.993Z","updated_at":"2024-11-05T10:15:14.515Z","avatar_url":"https://github.com/mxl.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# laravel-api-key\n[![Current version](https://img.shields.io/packagist/v/mxl/laravel-api-key.svg?logo=composer)](https://packagist.org/packages/mxl/laravel-api-key)\n[![Monthly Downloads](https://img.shields.io/packagist/dm/mxl/laravel-api-key.svg)](https://packagist.org/packages/mxl/laravel-api-key/stats)\n[![Total Downloads](https://img.shields.io/packagist/dt/mxl/laravel-api-key.svg)](https://packagist.org/packages/mxl/laravel-api-key/stats)\n[![Build Status](https://travis-ci.org/mxl/laravel-api-key.svg?branch=master)](https://travis-ci.org/mxl/laravel-api-key)\n\nAPI Key Authorization for Laravel with replay attack prevention\n\n## Installation\n\n```bash\n$ composer require mxl/laravel-api-key\n```\n\n## How it works?\n\nBoth sides (i.e. client and server) have a secret key.\nClient calculates a token - hash value for concatenated secret key and current timestamp.\nThe Token and the timestamp are sent with request to server as separate HTTP headers.\nServer recalculates hash value and validates the token by comparing it with this value and by checking that received timestamp belongs to current time ± window interval.\n\n## Configuration\n\nPackage uses default configuration from `vendor/laravel-api-key/config/apiKey.php`:\n```php\n\u003c?php\n\nreturn [\n    'secret' =\u003e env('API_KEY_SECRET'),\n    'hash' =\u003e env('API_KEY_HASH', 'md5'),\n    'timestampHeader' =\u003e env('API_KEY_TIMESTAMP_HEADER', 'X-Timestamp'),\n    'tokenHeader' =\u003e env('API_KEY_TOKEN_HEADER', 'X-Authorization'),\n    'window' =\u003e env('API_KEY_WINDOW', 30),\n];\n```\n\nTo change it set environment variables mentioned in this configuration or copy it to your project with:\n\n```bash\n$ php artisan vendor:publish --provider=\"MichaelLedin\\LaravelApiKey\\ApiKeyServiceProvider\" --tag=config\n```\n\nand modify `config/apiKey.php` file.\n\n\n**Notice!** If you use `php artisan config:cache` or `php artisan optimize` command then you have \nto publish configuration as described above otherwise `env()` function will return `null` for all environment variables.\n[Read more](https://laravel.com/docs/5.8/deployment#optimizing-configuration-loading).\n\nThe configuration has following parameters:\n- `secret` - secret key that is known by client and server;\n- `hash` - an algorithm used to create hash value from secret key and timestamp; for a list of supported algorithms check an output of [hash_algos](https://www.php.net/manual/en/function.hash-algos.php) function;\n- `timestampHeader` - HTTP header used to pass a timestamp;\n- `tokenHeader` - HTTP header used to pass a token;\n- `window` - window interval, in seconds;\n\n## Usage\n\nAssign the middleware to routes using middleware class name:\n\n```php\nuse \\MichaelLedin\\LaravelApiKey\\AuthorizeApiKey;\n\nRoute::get('admin/profile', function () {\n    //\n})-\u003emiddleware(AuthorizeApiKey::class);\n```\n\nor an alias:\n\n```php\nRoute::get('admin/profile', function () {\n    //\n})-\u003emiddleware('apiKey');\n```\n\n## Maintainers\n\n- [@mxl](https://github.com/mxl)\n\n## Other useful Laravel packages from the author\n\n- [mxl/laravel-queue-rate-limit](https://github.com/mxl/laravel-queue-rate-limit) - simple Laravel queue rate limiting;\n- [mxl/laravel-job](https://github.com/mxl/laravel-job) - dispatch a job from command line and more;\n\n## License\n\nSee the [LICENSE](https://github.com/mxl/laravel-api-key/blob/master/LICENSE) file for details.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxl%2Flaravel-api-key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmxl%2Flaravel-api-key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxl%2Flaravel-api-key/lists"}