{"id":24317398,"url":"https://github.com/fetchandadd/guardian","last_synced_at":"2026-05-19T02:08:57.145Z","repository":{"id":57069998,"uuid":"80766169","full_name":"fetchandadd/guardian","owner":"fetchandadd","description":"Authentication middleware for PSR-15","archived":false,"fork":false,"pushed_at":"2017-02-17T15:54:45.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-10T16:44:43.934Z","etag":null,"topics":["authentication","middleware","php","psr-15"],"latest_commit_sha":null,"homepage":"","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/fetchandadd.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":"2017-02-02T20:34:16.000Z","updated_at":"2018-11-08T00:07:53.000Z","dependencies_parsed_at":"2022-08-24T10:20:41.811Z","dependency_job_id":null,"html_url":"https://github.com/fetchandadd/guardian","commit_stats":null,"previous_names":["timtegeler/guardian"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/fetchandadd/guardian","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fetchandadd%2Fguardian","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fetchandadd%2Fguardian/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fetchandadd%2Fguardian/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fetchandadd%2Fguardian/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fetchandadd","download_url":"https://codeload.github.com/fetchandadd/guardian/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fetchandadd%2Fguardian/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263674233,"owners_count":23494538,"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":["authentication","middleware","php","psr-15"],"created_at":"2025-01-17T13:39:24.008Z","updated_at":"2026-05-19T02:08:57.080Z","avatar_url":"https://github.com/fetchandadd.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Guardian\n\n[![Build Status](https://travis-ci.org/timtegeler/guardian.svg?branch=master)](https://travis-ci.org/timtegeler/guardian)\n[![Coverage Status](https://coveralls.io/repos/github/timtegeler/guardian/badge.svg?branch=master)](https://coveralls.io/github/timtegeler/guardian?branch=master)\n[![GitHub license](https://img.shields.io/github/license/timtegeler/guardian.svg)]()\n\n**Guardian** provides an adapter between an authentication backend and your PSR-15 middleware stack\n\n- Compatible to the PSR-15 middleware interface \n- Adaptable to your authentication backend with a simple interface\n\n```php\n\u003c?php\n\n// create a new authentication backend which implements the AuthenticationInterface\n$authenticationBackend = new AuthenticationBackend();\n\n// using e.g. mindplay-dk/middleman as a dispatcher for the middleware stack\n$response = (new Dispatcher(\n    [   \n        // inject Guardian with the authentication backend instance\n        new Guardian($authenticationBackend),\n        // ... more middlwares e.g. a router\n        new Router()\n    ]\n))-\u003edispatch($request);\n```\n\n## Authentication Backend\n\nThe focus of Guardian is on the adaptation of an authentication backend with a PSR-15 middleware stack. \n\nThis means that Guardian itself is not capable of providing authentication e.g. [Basic access authentication](https://en.wikipedia.org/wiki/Basic_access_authentication). But Guardian ships with a simple interface that can be implemented by the authentication backend. The interface consists of two methods. \n \n```php\n\u003c?php\n\ninterface AuthenticationInterface\n{\n\n    /**\n     * @param ServerRequestInterface $request\n     * @return bool\n     */\n    public function authenticate(ServerRequestInterface $request);\n    \n    /**\n    * @return ResponseInterface\n    */\n    public function getAuthenticationFailedResponse();\n\n}\n```\n\n### authenticate\n\nThe `authenticate` method receives the current request as a parameter and must return a `boolean` (which stands for `access approved` respectively `access denied`) . \n\n### getAuthenticationFailedResponse\n\nThe `getAuthenticationFailedResponse` method must return a `ResponseInterface` instance. It's called by Guardian in case of `access denied` to return a `ResponseInterface` instance to the middleware pipeline. The fact that the authentication backend is in charge to provide a proper `ResponseInterface` instance is due to the need of custom properties.\n\nE.g. an authentication backend, which supports the [Basic access authentication](https://en.wikipedia.org/wiki/Basic_access_authentication), \"should return a response whose header contains a *HTTP 401 Unauthorized status* and a *WWW-Authenticate field.* The WWW-Authenticate field for basic authentication (used most often) is constructed as following:  `WWW-Authenticate: Basic realm=\"User Visible Realm\"`\" [[WIKI]](https://en.wikipedia.org/wiki/Basic_access_authentication#Server_side)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffetchandadd%2Fguardian","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffetchandadd%2Fguardian","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffetchandadd%2Fguardian/lists"}