{"id":26085269,"url":"https://github.com/codezero-be/oauth","last_synced_at":"2026-04-20T15:31:10.411Z","repository":{"id":31463950,"uuid":"35027836","full_name":"codezero-be/oauth","owner":"codezero-be","description":"Social authentication without the headaches.","archived":false,"fork":false,"pushed_at":"2015-05-05T12:26:58.000Z","size":128,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-06T15:51:30.405Z","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/codezero-be.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-04T10:07:53.000Z","updated_at":"2015-08-08T15:24:49.000Z","dependencies_parsed_at":"2022-09-03T16:22:52.018Z","dependency_job_id":null,"html_url":"https://github.com/codezero-be/oauth","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Foauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Foauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Foauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Foauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codezero-be","download_url":"https://codeload.github.com/codezero-be/oauth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242650948,"owners_count":20163611,"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-03-09T05:58:05.300Z","updated_at":"2025-12-05T15:04:13.540Z","avatar_url":"https://github.com/codezero-be.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OAuth\n\n[![GitHub release](https://img.shields.io/github/release/codezero-be/oauth.svg)]()\n[![License](https://img.shields.io/packagist/l/codezero/oauth.svg)]()\n[![Total Downloads](https://img.shields.io/packagist/dt/codezero/oauth.svg)](https://packagist.org/packages/codezero/oauth)\n\n### Social authentication without the headaches!\n\nThis package is a wrapper around [logical-and/php-oauth](https://github.com/logical-and/php-oauth) and aims to make it even easier to authenticate users via third party providers. Supports vanilla PHP and [Laravel 5](http://laravel.com/).\n\n## Installation\n\nInstall this package through Composer:\n\n    composer require codezero/oauth\n\n## Register Apps\n\nYou will need to create an App with each of the providers that you wish to support. They will give you an App ID (or key) and an App secret.\n\n## Vanilla PHP Implementation\n\n### Create a Configuration File\n\nCreate a `providers.php` configuration file and store your keys in it:\n\n    \u003c?php\n\n    return [\n        'facebook' =\u003e [\n            'key'    =\u003e '123',\n            'secret' =\u003e '456',\n        ],\n        'google' =\u003e [\n            'key'    =\u003e '123',\n            'secret' =\u003e '456',\n        ],\n        // ...\n    ];\n\n### Create a Script\n\nCreate a `.php` file and autoload the vendor classes:\n\n    require_once 'vendor/autoload.php'; // Path may vary\n\nNext, import and new up the classes:\n\n    use CodeZero\\OAuth\\Authenticator;\n    use CodeZero\\OAuth\\ProviderFactory;\n    \n    $credentials = include __DIR__.'/path/to/providers.php';\n    $providerFactory = new ProviderFactory($credentials);\n    $auth = new Authenticator($providerFactory);\n\nNow you have `$auth` to work with. Jump to [#usage](#usage) to see how easy it is... ;) \n\n## Laravel 5 Implementation\n\nAdd the ServiceProvider to the providers array in `config/app.php`:\n\n    'providers' =\u003e [\n        'CodeZero\\OAuth\\Laravel5\\OAuthServiceProvider'\n    ]\n\nCreate `oauth-providers.php` to the `config` folder and add your configuration array, or simply publish and edit it:\n \n    php artisan config:publish codezero/oauth\n    \nThen you can \"make\" (or inject) a `Authenticator` instance anywhere in your app:\n\n    $auth = \\App::make('CodeZero\\OAuth\\Contracts\\Authenticator');\n\nNow you have `$auth` to work with. Jump to [#usage](#usage) to see how easy it is... ;) \n\n## Usage\n\n### Redirect... Enjoy the ride!\n\nWith the `Authenticator` instance (`$auth`) you can call... Facebook (or Google, or...):\n\n    $details = $auth-\u003erequest('facebook'); //=\u003e Lower case!\n\nWhen you run `$auth-\u003erequest('provider')` you will first be redirected to the provider. You will need to grant or deny access to your personal information and then you will be redirected back to the page where you came from.\n\n**IMPORTANT:** You need to set your page as a valid callback URL in your App!\n\n\u003e Also note that this script will always append `?run=1` to the URL when you are redirected back. Depending on the provider, they are touchy about this. At least for Google this is very important, so make sure you include it in the callback URL in your App settings if needed!\n\n### Check the response...\n\nNow you can handle the `$details` that were returned by the provider:\n\n    if ($details) {\n        $email = $details-\u003egetEmail();\n        $firstName = $details-\u003egetFirstName();\n        $lastName = $details-\u003egetLastName();\n        // ...\n    } else {\n        // User canceled!\n    }\n\nIf the user declines, `$details` will be `false` and you can do whatever is needed.\n\nIf access is granted, `$details` will be an instance of `ExtractorInterface` from the [logical-and/php-oauth](https://github.com/logical-and/php-oauth) package, which has several handy methods to fetch specific user data. Please refer to [https://github.com/logical-and/php-oauth#userdata](https://github.com/logical-and/php-oauth#userdata) for more information on this or take a look at the [`interface`](https://github.com/logical-and/php-oauth/blob/master/src/UserData/Extractor/ExtractorInterface.php).\n\n### Redirect the users...\n\nWhen you get redirected back to your site after a successful request, you will notice that there is a token in the URL. This token can't be used twice, so if you would refresh the page an exception would be thrown...\n\nTherefor, it might be wise to redirect your users somewhere after you're done.\n\n## Available Providers\n\n`logical-and/php-oauth` supports [ALOT of different services](https://github.com/logical-and/php-oauth#service-support).\n\nEach of those can work with this package, as long as you add the nescessary keys to your configuration and there is a [Provider class](https://github.com/codezero-be/oauth/blob/master/src/Providers) available.\n\n### Create a Provider\n\nIf I didn't include a [supported](https://github.com/logical-and/php-oauth#service-support) provider yet, you can make one yourself: \n\n    use CodeZero\\OAuth\\BaseProvider;\n    \n    class ExampleProvider extends BaseProvider\n    {\n        /**\n         * Internal Provider Handle\n         *\n         * @var string\n         */\n        protected $handle = 'example';\n    \n        /**\n         * Default Scope\n         *\n         * @var array\n         */\n        protected $defaultScope = [ 'example.scope' ];\n    \n        /**\n         * Default Request Uri\n         *\n         * @var string\n         */\n        protected $defaultRequest = 'example/uri';\n    }\n\nThe handle needs to match the ones that are used in [php-oauth's examples](https://github.com/logical-and/php-oauth/tree/master/examples). Also the basic scope and request URI can be found there.\n\nJust save your class somewhere, make sure it's being (auto)loaded and then reference it in your configuration array like so:\n\n    'example' =\u003e [\n        'key'    =\u003e '123',\n        'secret' =\u003e '456',\n        'scope'          =\u003e [], // Optional: overrule default\n        'request_uri'    =\u003e '', // Optional: overrule default\n        'callback_url'   =\u003e '', // Optional: overrule default\n        'provider_class' =\u003e 'ExampleProvider', //=\u003e Your custom provider\n    ],\n\n## Examples\n\nTake a look at [examples](https://github.com/codezero-be/oauth/blob/master/examples).\n\n## ToDo\n\n- Add tests...\n- Add more providers...\n- Create storage driver for Laravel's Session...\n- Fix bugs (maybe... probably...) :)\n\n## Testing\n\n    $ vendor/bin/phpspec run\n\n## Security\n\nIf you discover any security related issues, please [e-mail me](mailto:ivan@codezero.be) instead of using the issue tracker.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n---\n[![Analytics](https://ga-beacon.appspot.com/UA-58876018-1/codezero-be/oauth)](https://github.com/igrigorik/ga-beacon)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodezero-be%2Foauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodezero-be%2Foauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodezero-be%2Foauth/lists"}