{"id":28676464,"url":"https://github.com/code16/machina","last_synced_at":"2025-08-01T08:13:34.568Z","repository":{"id":30292873,"uuid":"124414307","full_name":"code16/machina","owner":"code16","description":"Machine to Machine Laravel authentication package based on JWT","archived":false,"fork":false,"pushed_at":"2025-03-10T13:40:54.000Z","size":49,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-13T11:56:33.599Z","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/code16.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-08T15:56:20.000Z","updated_at":"2025-03-10T13:39:46.000Z","dependencies_parsed_at":"2025-03-10T14:24:14.794Z","dependency_job_id":"04fbeee1-753a-42ad-97c5-7623c58c6aa5","html_url":"https://github.com/code16/machina","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/code16/machina","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code16%2Fmachina","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code16%2Fmachina/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code16%2Fmachina/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code16%2Fmachina/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code16","download_url":"https://codeload.github.com/code16/machina/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code16%2Fmachina/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259686859,"owners_count":22896086,"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":"2025-06-13T23:04:46.383Z","updated_at":"2025-06-13T23:04:48.019Z","avatar_url":"https://github.com/code16.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Machina\n\nThis package is a wrapper around `tymons\\jwt-auth`, aimed at providing a simple \u0026 flexible machine-to-machine authentication for Laravel 5.5+. \n\n## Installation\n\n```\n    composer require code16/machina\n```\n\n## Configuration\n\nIf you want to customize some default options like the prefix used for `/login` and `/refresh` endpoints by the package, you can publish it to your application folder : \n\n```\n    php artisan config:publish code16/machina\n```\n\nThen run this command, which will add a `JWT_SECRET` entry in your `.env` file:\n\n```\n    php artisan jwt:secret\n```\n\n### Defining machine guard\n\nIn `config/auth.php` : \n\n```php\n    'guards' =\u003e [\n        'web' =\u003e [\n            'driver' =\u003e 'session',\n            'provider' =\u003e 'users',\n        ],\n\n        'machina' =\u003e [\n            'driver' =\u003e 'machina',\n            'provider' =\u003e Api\\ClientRepository::class,\n        ],\n    ],\n```\n\n### Creating a `ClientRepository` class \n\nThis package does not come with an opinionated way of retrieving clients, but instead provides a very simple way to adapt it to your application, by providing a class implementing `Code16\\Machina\\ClientRepositoryInterface`. \n\nExample :\n\n```php\n\n    namespace App;\n\n    use Code16\\Machina\\ClientRepositoryInterface;\n\n    class ClientRepository implements ClientRepositoryInterface\n    {\n        public function findByKey($key)\n        {\n            return User::find($key);\n        }\n\n        public function findByCredentials($client, $secret)\n        {\n            return User::where('id', $client)-\u003ewhere('secret', $secret)-\u003efirst();\n        }\n\n    }\n\n```\n\nNote that here we used the standard `App\\User` model DB to identify our client, but you can use whichever model / fields you like. \n\n## Protecting routes\n\n```\n    Route::get('protected', 'ApiController@index')-\u003emiddleware('auth:machina');\n```\n\n## Authenticating and retrieving token\n\nSend a POST request the `/auth/login` endpoint with `client` and `secret` as parameters : \n\n```\n    {\n        client : \"1\",\n        secret : \"x7jfajleug64hggi\"\n    }\n```\n\nIf the credentials are correct, the API will return a JWT token that can be used to access protected routes. \n\n## Accessing protected routes\n\nThere is two ways of passing the token along the request : \n\n- Passing the token in the `authorization` header with the following string format : `Bearer \u003ctoken\u003e`\n\n- Passing the token as a query parameter : `https://app.dev/protected?token=\u003ctoken\u003e`\n\n## Implementing client applications\n\nFor your client applications, you can use our companion package, [machina client](https://github.com/code16/machina-client).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode16%2Fmachina","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode16%2Fmachina","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode16%2Fmachina/lists"}