{"id":22941789,"url":"https://github.com/zacksleo/yii2-oauth2","last_synced_at":"2025-08-12T21:32:26.731Z","repository":{"id":57089051,"uuid":"117953253","full_name":"zacksleo/yii2-oauth2","owner":"zacksleo","description":"yii2 oauth2 module","archived":false,"fork":false,"pushed_at":"2018-11-28T10:33:50.000Z","size":69,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-13T14:55:09.463Z","etag":null,"topics":["oauth2-server","yii2","yii2-extension","yii2-oauth2","yii2-oauth2-server"],"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/zacksleo.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-01-18T08:15:29.000Z","updated_at":"2019-03-06T01:27:44.000Z","dependencies_parsed_at":"2022-08-20T16:00:28.742Z","dependency_job_id":null,"html_url":"https://github.com/zacksleo/yii2-oauth2","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksleo%2Fyii2-oauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksleo%2Fyii2-oauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksleo%2Fyii2-oauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksleo%2Fyii2-oauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zacksleo","download_url":"https://codeload.github.com/zacksleo/yii2-oauth2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229710708,"owners_count":18111640,"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":["oauth2-server","yii2","yii2-extension","yii2-oauth2","yii2-oauth2-server"],"created_at":"2024-12-14T13:45:03.282Z","updated_at":"2024-12-14T13:45:03.925Z","avatar_url":"https://github.com/zacksleo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yii2-oauth2\n\nyii2 oauth2 module based on [yii2-oauth2-server](https://github.com/Filsh/yii2-oauth2-server)\n\n\n[![Latest Stable Version](https://poser.pugx.org/zacksleo/yii2-oauth2/version)](https://packagist.org/packages/zacksleo/yii2-oauth2)\n[![Total Downloads](https://poser.pugx.org/zacksleo/yii2-oauth2/downloads)](https://packagist.org/packages/zacksleo/yii2-oauth2)\n[![License](https://poser.pugx.org/zacksleo/yii2-oauth2/license)](https://packagist.org/packages/zacksleo/yii2-oauth2)\n[![StyleCI](https://styleci.io/repos/117953253/shield?branch=master)](https://styleci.io/repos/117953253)\n[![Code Climate](https://img.shields.io/codeclimate/github/zacksleo/yii2-oauth2.svg)]()\n[![Build Status](https://travis-ci.org/zacksleo/yii2-oauth2.svg?branch=master)](https://travis-ci.org/zacksleo/yii2-oauth2)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/zacksleo/yii2-oauth2/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/zacksleo/yii2-oauth2/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/zacksleo/yii2-oauth2/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/zacksleo/yii2-oauth2/?branch=master)\n[![Build Status](https://scrutinizer-ci.com/g/zacksleo/yii2-oauth2/badges/build.png?b=master)](https://scrutinizer-ci.com/g/zacksleo/yii2-oauth2/build-status/master)\n\n\n## Install\n\n```\ncomposer install zacksleo/yii2-oauth2\n\n```\n\n## Migration Database\n\n\n```\n./yii migrate --migrationPath=@vendor/zacksleo/yii2-oauth2/migrations\n\n```\n\n## Config module\n\n### for API or frontend\n\n```php\n\n 'modules' =\u003e [\n     'oauth2' =\u003e [\n         'class' =\u003e 'filsh\\yii2\\oauth2server\\Module',\n         /* Fix Yii2 2.0.13+ Incompatible Issue\n          * @see https://github.com/Filsh/yii2-oauth2-server/issues/132\n          */\n         'components' =\u003e [\n            'request' =\u003e function () {\n                return \\filsh\\yii2\\oauth2server\\Request::createFromGlobals();\n            },\n            'response' =\u003e [\n                'class' =\u003e \\filsh\\yii2\\oauth2server\\Response::class,\n            ],\n         ],\n         'tokenParamName' =\u003e 'access_token',\n         'tokenAccessLifetime' =\u003e 3600 * 24 * 7,\n         'storageMap' =\u003e [\n             'user_credentials' =\u003e 'common\\models\\User',\n             'access_token' =\u003e 'zacksleo\\yii2\\oauth2\\common\\models\\storage\\AccessToken',\n         ],\n         'grantTypes' =\u003e [\n             'client_credentials' =\u003e [\n                 'class' =\u003e 'OAuth2\\GrantType\\ClientCredentials',\n                 'allow_public_clients' =\u003e false\n             ],\n             'user_credentials' =\u003e [\n                 'class' =\u003e 'OAuth2\\GrantType\\UserCredentials',\n             ],\n             'refresh_token' =\u003e [\n                 'class' =\u003e 'OAuth2\\GrantType\\RefreshToken',\n                 'always_issue_new_refresh_token' =\u003e true,\n             ],\n             'authorization_code' =\u003e [\n                 'class' =\u003e 'OAuth2\\GrantType\\AuthorizationCode',\n                 'require_exact_redirect_uri' =\u003e false,\n             ]\n         ]\n     ]\n ]\n\n```\n\n### for backend\n\n```php\n\n  'modules' =\u003e [\n      'oauth2' =\u003e [\n          'class' =\u003e 'zacksleo\\yii2\\oauth2\\backend\\Module',\n      ]\n  ]\n\n```\n\n## Token Controller\n\n```php\n\u003c?php\n\nnamespace api\\modules\\v1\\controllers;\n\nclass TokenController extends \\zacksleo\\yii2\\oauth2\\api\\controllers\\TokenController\n{\n\n}\n\n```\n\n## Api with Token Authorization\n\n```php\nclass ResourceController extends \\zacksleo\\yii2\\oauth2\\api\\controllers\\Oauth2Controller \n{\n\n}\n\n```\n\n## Config common\\models\\User\n\n```php\n\u003c?php\n\nnamespace common\\models;\n\nuse OAuth2\\Storage\\UserCredentialsInterface;\nuse yii;\nuse yii\\db\\ActiveRecord;\nuse yii\\web\\IdentityInterface;\nuse yii\\behaviors\\TimestampBehavior;\nuse filsh\\yii2\\oauth2server\\exceptions\\HttpException;\nuse zacksleo\\yii2\\oauth2\\common\\helpers\\Predis;\n\n/**\n * User model\n *\n * @property integer $id\n * @property string $phone\n * @property string $created_at\n * @property string $updated_at\n * @property string $union_id\n */\nclass User extends ActiveRecord implements IdentityInterface, UserCredentialsInterface\n{\n    /**\n     * @inheritdoc\n     */\n    public static function findIdentity($id)\n    {\n        return static::findOne($id);\n    }\n\n    /**\n     * @inheritdoc\n     */\n    public static function findIdentityByAccessToken($token, $type = null)\n    {\n        $oauthAccessToken = Predis::getInstance()-\u003egetClient()-\u003egetToken($token);\n        if (empty($oauthAccessToken)) {\n            throw new yii\\web\\UnauthorizedHttpException('Unauthorized');\n        }\n        $model = static::findOne(['union_id' =\u003e $oauthAccessToken['union_id']]);\n        return $model;\n    }\n\n    /**\n     * Implemented for Oauth2 Interface\n     * @param $username\n     * @param $password\n     * @return bool\n     * @throws HttpException\n     */\n    public function checkUserCredentials($username, $password)\n    {\n    }\n\n    /**\n     * Implemented for Oauth2 Interface\n     * @param $username\n     * @return array\n     */\n    public function getUserDetails($username)\n    {\n     }\n\n    /**\n     * @inheritdoc\n     */\n    public function getId()\n    {\n        return $this-\u003egetPrimaryKey();\n    }\n\n    public function getUnionId()\n    {\n        return $this-\u003eunion_id;\n    }\n}\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzacksleo%2Fyii2-oauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzacksleo%2Fyii2-oauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzacksleo%2Fyii2-oauth2/lists"}