{"id":20510704,"url":"https://github.com/battis/restful-api.user-session","last_synced_at":"2025-10-13T18:35:44.246Z","repository":{"id":58645900,"uuid":"532919529","full_name":"battis/restful-api.user-session","owner":"battis","description":"[READ-ONLY] User session management for Slim Framework","archived":false,"fork":false,"pushed_at":"2024-03-18T19:31:13.000Z","size":194,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-27T13:04:28.198Z","etag":null,"topics":["authentication","session-management","slim-framework","user-sessions"],"latest_commit_sha":null,"homepage":"https://github.com/battis/restful-api/tree/main/packages/user-session","language":"PHP","has_issues":false,"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/battis.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":"2022-09-05T13:45:07.000Z","updated_at":"2024-03-18T21:26:07.000Z","dependencies_parsed_at":"2024-03-18T19:56:39.041Z","dependency_job_id":"b1ba5e92-4e21-4c2d-88e9-db0c7e32cea3","html_url":"https://github.com/battis/restful-api.user-session","commit_stats":{"total_commits":32,"total_committers":2,"mean_commits":16.0,"dds":0.0625,"last_synced_commit":"3876180d6f83aac77abd1f9e10b6d2dbda5fc7c5"},"previous_names":["battis/user-session"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/battis%2Frestful-api.user-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/battis%2Frestful-api.user-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/battis%2Frestful-api.user-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/battis%2Frestful-api.user-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/battis","download_url":"https://codeload.github.com/battis/restful-api.user-session/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242115537,"owners_count":20074201,"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","session-management","slim-framework","user-sessions"],"created_at":"2024-11-15T20:30:45.369Z","updated_at":"2025-10-13T18:35:44.146Z","avatar_url":"https://github.com/battis.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Battis\\UserSession\n\n[![Latest Version](https://img.shields.io/packagist/v/battis/user-session.svg)](https://packagist.org/packages/battis/user-session)\n[![codecov](https://codecov.io/gh/battis/user-session/branch/main/graph/badge.svg)](https://codecov.io/gh/battis/user-session)\n\nUser session management for Slim Framework\n\n## Installation\n\n```bash\ncomposer install battis/user-session\n```\n\n## Use\n\nSee [example](https://github.com/battis/restful-api/tree/main/examples/user-session) for sample implementation. The highlights are:\n\n### Add `UserSession\\Dependencies` definitions\n\nUse `UserSession\\Dependencies` to prepare container with dependency definitions (this should be done _before_ any additional app-specific definitions wherein you might want to override any of the UserSession defaults):\n\n```php\n/** @var DI\\ContainerBuilder $containerBuilder */\n$containerBuilder-\u003eaddDefinitions(\n  Battis\\UserSession\\Dependencies::definitions()\n);\n```\n\n### Implement `UserEntityInterface` \u0026 `UserRepositoryInterface`\n\nDefine implementations of `UserEntityInterface` and `UserRepositoryInterface` and\n\n```php\nnamespace Example;\n\nclass UserEntity implements Battis\\UserSession\\Entities\\UserEntityInterface\n{\n  public function getIdentifier(): string\n  {\n    // ...\n  }\n\n  public function passwordVerify(string $password): bool\n  {\n    // ...\n  }\n}\n```\n\n```php\n\u003c?php\n\nnamespace Example;\n\nclass UserRepository implements Battis\\UserSession\\Repositories\\UserRepositoryInterface\n{\n  public function getUserEntityByUsername(\n    // ...\n  }\n}\n```\n\nDefine these implementations (or, at least, your `UserRepositoryInterface` implementation) in the container:\n\n```php\n/** @var DI\\ContainerBuilder $containerBuilder */\n$containerBuilder-\u003eaddDefinitions([\n  Battis\\UserSession\\Repositories\\UserRepositoryInterface::class =\u003e fn() =\u003e new Example\\UserRepository(),\n]);\n```\n\n### Define `/auth` endpoints\n\nUse `UserSession\\Controller` to define authentication endpoints (`/auth/login` and `/auth/logout`):\n\n```php\n/** @var Slim\\App $app */\n$app-\u003egroup(\n  Battis\\UserSession\\Controller::ENDPOINT,\n  Battis\\UserSession\\Controller::class\n);\n```\n\n### Use `Session` or `RequireAuthentication` middleware\n\nAdd a user session that provides access to the currently logged-in user to an endpoint (or group) by adding the `UserSession\\Middleware\\Session` middleware:\n\n```php\n/** @var Slim\\App $app */\n$app\n  -\u003eget('/home', Example\\PageRenderer::class)\n  -\u003eadd(Battis\\UserSession\\Middleware\\Session::class);\n```\n\nRestrict access to an endpoint (or group) to authenticated users by adding the `UserSession\\Middleware\\RequireAuthentication` middleware:\n\n```php\n/** @var Slim\\App $app */\n$app\n  -\u003eget('/protected', Example\\PageRenderer::class)\n  -\u003eadd(Battis\\UserSession\\Middleware\\RequireAuthentication::class);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbattis%2Frestful-api.user-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbattis%2Frestful-api.user-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbattis%2Frestful-api.user-session/lists"}