{"id":22894263,"url":"https://github.com/clearcodehq/eh-library-template","last_synced_at":"2025-07-31T16:16:34.338Z","repository":{"id":69040370,"uuid":"49630629","full_name":"ClearcodeHQ/eh-library-template","owner":"ClearcodeHQ","description":"Template for EH library exercise in REST API course, written using Slim Framework","archived":false,"fork":false,"pushed_at":"2016-03-04T09:04:14.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-30T13:37:08.717Z","etag":null,"topics":[],"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/ClearcodeHQ.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":"2016-01-14T07:35:32.000Z","updated_at":"2016-01-14T08:04:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"cb90667e-fe7e-4895-8a1c-ce7990f14f39","html_url":"https://github.com/ClearcodeHQ/eh-library-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClearcodeHQ%2Feh-library-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClearcodeHQ%2Feh-library-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClearcodeHQ%2Feh-library-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClearcodeHQ%2Feh-library-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ClearcodeHQ","download_url":"https://codeload.github.com/ClearcodeHQ/eh-library-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246552972,"owners_count":20795835,"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-12-13T23:17:21.339Z","updated_at":"2025-03-31T22:38:36.642Z","avatar_url":"https://github.com/ClearcodeHQ.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Installation\n\n```\n$ composer install\n$ php bin/loadUsers.php\n```\n\nloadUsers adds a librarian user to the database (librarian@example.com)\n\n## Start\n\n```\n$ cd web\n$ php -S \u003caddr\u003e:\u003cport\u003e index.php\n```\n\nopen `http://\u003caddr\u003e:\u003cport\u003e/test` in your browser, you should see\n\n```\nIt works!\nyou can see that these properties were injected using dependency injection container\nwhich you can use to add your own services if needed to the task\nauth property is of class Clearcode\\EHLibraryAuth\\Application\nlibrary property is of class Clearcode\\EHLibrary\\Application\n```\n\n## Application template\n\n### Actions\n\nauthentication and authorization middleware is added to all actions in [app.php](https://github.com/ClearcodeHQ/eh-library-template/blob/master/src/app.php)\nthat need to be protected\n\n### Placeholders\n\nplaceholders can be found in:\n* [app.php](https://github.com/ClearcodeHQ/eh-library-template/blob/master/src/app.php)\n* [AuthenticationMiddleware.php](https://github.com/ClearcodeHQ/eh-library-template/blob/master/src/Middleware/AuthenticationMiddleware.php)\n* [AuthorizationMiddleware.php](https://github.com/ClearcodeHQ/eh-library-template/blob/master/src/Middleware/AuthorizationMiddleware.php)\n\n#### log in example\n\nthis placeholder is for implementation of user log in. In this current example **password is not used, user is logged in only by email** for the sake of simplicity.\n\nstudent is required to design:\n* how does the url look\n* how the request arguments are passed to the action\n* what HTTP method is to be used here\n* how user email is acquired (needed for getUser)\n* what happens when the user does not exist (how should the response look like)\n* how to generate and pass a JWT to the response in case user logs in successfully\n\n\n```php\n//Login user (login by email only - no password)\n$app-\u003emap(['\u003cmethod\u003e'], '\u003curl\u003e', function(ServerRequestInterface $request, ResponseInterface $response, $args = []) {\n\n    /* your code here */\n\n    $user = $this-\u003eauth-\u003egetUser(/* arguments */);\n\n    if (!$user instanceof User) {\n        /* your code here */\n    }\n\n    $token = $this-\u003eauth-\u003egenerateToken(/* arguments */);\n\n    /* your code here */\n\n    return $response;\n});\n```\n\n#### authentication with JWT\n\nthis placeholder is from [AuthenticationMiddleware.php](https://github.com/ClearcodeHQ/eh-library-template/blob/master/src/Middleware/AuthenticationMiddleware.php) which is used to authenticate the user using JWT\n\nhere the student designs:\n* how to pass JWT in a request and use it to authenticate the user ($token is an argument in LibraryAuth::authenticate)\n* how to handle exceptions thrown by authenticate method\n* how the response should look like when user does not exist\n\n```php\npublic function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)\n{\n    /* your code here */\n\n    $this-\u003eauth-\u003eauthenticate(/* arguments */);\n\n    /* your code here */\n\n    $token = (new Parser())-\u003eparse(/* arguments */);\n\n    $user = $this-\u003eauth-\u003egetUser($token-\u003egetClaim('email'));\n\n    if (!$user instanceof User) {\n        /* your code here */\n    }\n\n    $request = $request-\u003ewithAttribute('user', $user);\n    $response = $next($request, $response);\n\n    return $response;\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclearcodehq%2Feh-library-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclearcodehq%2Feh-library-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclearcodehq%2Feh-library-template/lists"}