{"id":19406278,"url":"https://github.com/chadicus/slim-oauth2-routes","last_synced_at":"2025-10-10T22:49:55.083Z","repository":{"id":35028867,"uuid":"39138798","full_name":"chadicus/slim-oauth2-routes","owner":"chadicus","description":"OAuth2 routes for use within a Slim Framework API","archived":false,"fork":false,"pushed_at":"2023-05-09T20:04:50.000Z","size":602,"stargazers_count":8,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T16:19:11.607Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chadicus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","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":"2015-07-15T13:38:06.000Z","updated_at":"2023-05-09T20:04:16.000Z","dependencies_parsed_at":"2024-06-18T21:11:50.492Z","dependency_job_id":"0e1d043e-5cb9-4a7d-bbac-c2167611b762","html_url":"https://github.com/chadicus/slim-oauth2-routes","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Fslim-oauth2-routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Fslim-oauth2-routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Fslim-oauth2-routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Fslim-oauth2-routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chadicus","download_url":"https://codeload.github.com/chadicus/slim-oauth2-routes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250600623,"owners_count":21456996,"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-10T11:41:52.153Z","updated_at":"2025-10-10T22:49:50.052Z","avatar_url":"https://github.com/chadicus.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chadicus\\Slim\\OAuth2\\Routes\n\n[![Build Status](https://travis-ci.org/chadicus/slim-oauth2-routes.svg?branch=master)](https://travis-ci.org/chadicus/slim-oauth2-routes)\n[![Code Quality](https://scrutinizer-ci.com/g/chadicus/slim-oauth2-routes/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/chadicus/slim-oauth2-routes/?branch=master)\n[![Code Coverage](https://coveralls.io/repos/github/chadicus/slim-oauth2-routes/badge.svg?branch=master)](https://coveralls.io/github/chadicus/slim-oauth2-routes?branch=master)\n\n[![Latest Stable Version](https://poser.pugx.org/chadicus/slim-oauth2-routes/v/stable)](https://packagist.org/packages/chadicus/slim-oauth2-routes)\n[![Latest Unstable Version](https://poser.pugx.org/chadicus/slim-oauth2-routes/v/unstable)](https://packagist.org/packages/chadicus/slim-oauth2-routes)\n[![License](https://poser.pugx.org/chadicus/slim-oauth2-routes/license)](https://packagist.org/packages/chadicus/slim-oauth2-routes)\n\n[![Total Downloads](https://poser.pugx.org/chadicus/slim-oauth2-routes/downloads)](https://packagist.org/packages/chadicus/slim-oauth2-routes)\n[![Daily Downloads](https://poser.pugx.org/chadicus/slim-oauth2-routes/d/daily)](https://packagist.org/packages/chadicus/slim-oauth2-routes)\n[![Monthly Downloads](https://poser.pugx.org/chadicus/slim-oauth2-routes/d/monthly)](https://packagist.org/packages/chadicus/slim-oauth2-routes)\n\n[![Documentation](https://img.shields.io/badge/reference-phpdoc-blue.svg?style=flat)](http://pholiophp.org/chadicus/slim-oauth2-routes)\n\n[OAuth2 Server](http://bshaffer.github.io/oauth2-server-php-docs/) route callbacks for use within a [Slim 3 Framework](http://www.slimframework.com/) API\n\n## Requirements\n\nChadicus\\Slim\\OAuth2\\Routes requires PHP 5.6 (or later).\n\n## Composer\nTo add the library as a local, per-project dependency use [Composer](http://getcomposer.org)! Simply add a dependency on\n`chadicus/slim-oauth2-routes` to your project's `composer.json` file such as:\n\n```sh\ncomposer require chadicus/slim-oauth2-routes\n```\n\n## Contact\nDevelopers may be contacted at:\n\n * [Pull Requests](https://github.com/chadicus/slim-oauth2-routes/pulls)\n * [Issues](https://github.com/chadicus/slim-oauth2-routes/issues)\n\n## Project Build\nWith a checkout of the code get [Composer](http://getcomposer.org) in your PATH and run:\n\n```sh\n./composer install\n./vendor/bin/phpunit\n```\n\n## A Note on Using Views\nThe `authorize` and `receive-code` route require `view` objects. The given view object must implement a render method such as the one found in [slim/twig-view](https://github.com/slimphp/Twig-View/blob/master/src/Twig.php#L103) and [slim/php-view](https://github.com/slimphp/PHP-View/blob/master/src/PhpRenderer.php#L64). It would be best if there was a common `ViewInterface` which both implementing but as of now such an interface does not exist.\n\n## Community\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/slim-oauth2/Lobby#)\n\n## Example Usage\n```php\nuse Chadicus\\Slim\\OAuth2\\Routes;\nuse OAuth2;\nuse OAuth2\\GrantType;\nuse OAuth2\\Storage;\nuse Slim;\nuse Slim\\Views;\n\n//Set-up the OAuth2 Server\n$storage = new Storage\\Pdo(array('dsn' =\u003e $dsn, 'username' =\u003e $username, 'password' =\u003e $password));\n$server = new OAuth2\\Server($storage);\n$server-\u003eaddGrantType(new GrantType\\AuthorizationCode($storage));\n$server-\u003eaddGrantType(new GrantType\\ClientCredentials($storage));\n\n//Set-up the Slim Application\n$app = new Slim\\App(\n    [\n        'view' =\u003e new Views\\PhpRenderer('/path/to/chadicus/slim-oauth2-routes/templates'),\n    ]\n);\n\n$container = $app-\u003egetContainer();\n\n$app-\u003emap(['GET', 'POST'], Routes\\Authorize::ROUTE, new Routes\\Authorize($server, $container['view']))-\u003esetName('authorize');\n$app-\u003epost(Routes\\Token::ROUTE, new Routes\\Token($server))-\u003esetName('token');\n$app-\u003emap(['GET', 'POST'], Routes\\ReceiveCode::ROUTE, new Routes\\ReceiveCode($container['view']))-\u003esetName('receive-code');\n$app-\u003epost(Routes\\Revoke::ROUTE, new Routes\\Revoke($server))-\u003esetName('revoke');\n\n//Add custom routes\n$slim-\u003eget('/foo', function($request, $response, $args) {\n    $authorization = $request-\u003egetHeaderLine('Authorization');\n\n    //validate access token against your storage\n\n    return $response-\u003ewithStatus(200);\n});\n\n//run the app\n$app-\u003erun();\n```\n## Authorize and The UserIdProvider\nWithin the Authorization route, you can define a  `UserIdProviderInterface` to extract the user_id from the incoming request. By default the\nroute will look in the `GET` query params.\n\n```php\n\nclass ArgumentUserIdProvider implements UserIdProviderInterface\n{\n\tpublic function getUserId(ServerRequestInterface $request, array $arguments)\n\t{\n\t\treturn isset($arguments['user_id']) ? $arguments['user_id'] : null;\n\t}\n}\n\n//middleware to add user_id to route parameters\n$loginMiddelware = function ($request, $response, $next) {\n\t// Validate the user credentials\n\t$userId = MyUserService::getUserIdIfValidCredentials($request);\n\tif ($userId === false) {\n\t\treturn $response-\u003ewithStatus(303);\n\t}\n\n\t//Put user_id into the route parameters\n\t$route = $request-\u003egetAttribute('route');\n\t$route-\u003esetArgument('user_id', $userId);\n\n\t//Credentials are valid, continue so the authorization code can be sent to the clients callback_uri\n\treturn $next($request, $response);\n};\n\n$authorizeRoute = new Routes\\Authorize($server, $view, 'authorize.phtml', new ArgumentUserIdProvider());\n$app-\u003emap(\n\t['GET', 'POST'],\n\tRoutes\\Authorize::ROUTE,\n\t$authorizeRoute\n)-\u003eadd($loginMiddleware)-\u003esetName('authorize');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadicus%2Fslim-oauth2-routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchadicus%2Fslim-oauth2-routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadicus%2Fslim-oauth2-routes/lists"}