{"id":18750680,"url":"https://github.com/webiny/oauth2","last_synced_at":"2025-04-12T23:32:23.034Z","repository":{"id":20228192,"uuid":"23500046","full_name":"webiny/OAuth2","owner":"webiny","description":"[READ-ONLY] PHP component provides wrappers for several OAuth2 systems like Facebook, LinkedIn and Google. (master at Webiny/Framework)","archived":false,"fork":false,"pushed_at":"2017-11-26T21:25:08.000Z","size":38,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-26T18:06:11.104Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.webiny.com/","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/webiny.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-08-30T20:24:53.000Z","updated_at":"2023-05-25T02:10:54.000Z","dependencies_parsed_at":"2022-08-22T15:40:26.755Z","dependency_job_id":null,"html_url":"https://github.com/webiny/OAuth2","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FOAuth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FOAuth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FOAuth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FOAuth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/OAuth2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"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-07T17:12:49.228Z","updated_at":"2025-04-12T23:32:21.721Z","avatar_url":"https://github.com/webiny.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"OAuth2 Wrappers\n==============\n\nThis component provides wrappers for several OAuth2 systems like Facebook, LinkedIn and Google.\nAfter you have gained OAuth2 access token, you can use this wrapper to communicate with the the desired service.\n\nInstall the component\n---------------------\nThe best way to install the component is using Composer.\n\n```bash\ncomposer require webiny/oauth2\n```\nFor additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/oauth2).\n\n## Supported OAuth2 servers\n\nCurrent supported OAuth2 servers are:\n\n* Facebook\n* Google\n* LinkedIn\n\n## Configuring the component\n\nTo use the component, you first need to configure it.\nThe configuration is done by defining the following params:\n\n- **Server** - class that will be used to process the response from OAuth2 server\n- **ClientId** - OAuth2 client id\n- **ClientSecret** - OAuth2 client secret\n- **Scope** - scope parameter based on the selected OAuth2 server\n- **RedirectUri** - location where the user will be redirected by the OAuth2 server once he is authorized\n\n### Example configuration:\n\n```yaml\n    OAuth2:\n        Facebook:\n            Server: \\Webiny\\Component\\OAuth2\\Server\\Facebook\n            ClientId: 273234862555915\n            ClientSecret: fe5G55632eeabc2086f8209a3ff05g22\n            Scope: email\n            RedirectUri: '/security/login-fb/'\n        GPlus:\n            Server: \\Webiny\\Component\\OAuth2\\Server\\Google\n            ClientId: 716241231612.apps.googleusercontent.com\n            ClientSecret: KyP8Eag3a60Jgb3mkgiuPFdZYl\n            Scope: openid%20profile%20email\n            RedirectUri: '/security/login-gp/'\n```\n\n## Usage\n\nThis component depends on users access token, without it no API call to the OAuth2 server can be made.\nTo get the access token, please read the implementation guide for a specific server you wish to use.\nOAuth2 components is also integrated with the `Security` component as a user and authentication provider, automating the process of getting the required auth token.\n\nExample:\n```php\n// load instance of `GPlus` configuration\n$instance = OAuth2Loader::getInstance('GPlus');\n\n// set access token\n$instance-\u003esetAccessToken('...');\n\n// do API requests to get user details\n$userProfile = $instance-\u003erequest()-\u003egetUserDetails();\n\n// do an API request to a specific API method\n$result = $instance-\u003erequest()-\u003erawRequest($url, $params);\n```\n\n## Registering additional servers\n\nFirst create a class that extends `\\Webiny\\Component\\OAuth2\\AbstractServer` and then implement the abstract methods.\nAll of the abstract methods are described inside `AbstractServer` class, and additionally you should also check out how\nimplementations of current servers looks like. They are located in `\\Webiny\\Component\\OAuth2\\Server` folder.\n\n```php\nclass Instagram extends \\Webiny\\Component\\OAuth2\\AbstractServer\n{\n    public function getAuthorizeUrl(){\n        // TODO: Implement _getUserDetailsTargetData() method.\n    }\n\n    public function getAccessTokenUrl(){\n        // TODO: Implement _getUserDetailsTargetData() method.\n    }\n\n\tprotected function _getUserDetailsTargetData() {\n\t\t// TODO: Implement _getUserDetailsTargetData() method.\n\t}\n\n\tprotected function _processUserDetails($result) {\n\t\t// TODO: Implement _processUserDetails() method.\n\t}\n\n\tpublic function processAuthResponse($response) {\n\t\t// TODO: Implement processAuthResponse() method.\n\t}\n}\n```\n\nOnce you have implemented your logic for the abstract methods, it's time to register the class with the OAuth2 component.\nIn order to do so, inside your config file, set the value of `Server` property to your newly created class.\n\n```yaml\n    OAuth2:\n        Instagram:\n            Server: \\MyLib\\OAuth2\\Server\\Instagram\n            ...\n```\n\nAnd you're done!\nTo use it, just configure it the same way as the built in classes.\n\n## Notice\n\nThe code on this component is not fully covered by unit test. Only main classes are tested, while tests for `Bridge` and `Server` still need to be written.\n\nResources\n---------\n\nTo run unit tests, you need to use the following command:\n\n    $ cd path/to/Webiny/Component/OAuth2/\n    $ composer.phar install\n    $ phpunit","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Foauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Foauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Foauth2/lists"}