{"id":21101413,"url":"https://github.com/librecmscom/yuncms-oauth2","last_synced_at":"2025-06-20T20:39:47.465Z","repository":{"id":57088529,"uuid":"110681804","full_name":"librecmscom/yuncms-oauth2","owner":"librecmscom","description":"The OAuth2 module for the yuncms.","archived":false,"fork":false,"pushed_at":"2018-01-31T10:11:25.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-14T08:13:19.202Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/librecmscom.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}},"created_at":"2017-11-14T11:28:53.000Z","updated_at":"2017-11-14T11:37:48.000Z","dependencies_parsed_at":"2022-08-20T15:30:08.037Z","dependency_job_id":null,"html_url":"https://github.com/librecmscom/yuncms-oauth2","commit_stats":null,"previous_names":["yuncms/yuncms-oauth2"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/librecmscom/yuncms-oauth2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librecmscom%2Fyuncms-oauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librecmscom%2Fyuncms-oauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librecmscom%2Fyuncms-oauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librecmscom%2Fyuncms-oauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/librecmscom","download_url":"https://codeload.github.com/librecmscom/yuncms-oauth2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librecmscom%2Fyuncms-oauth2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261013838,"owners_count":23097119,"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-19T23:46:10.746Z","updated_at":"2025-06-20T20:39:42.446Z","avatar_url":"https://github.com/librecmscom.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yuncms-oauth2\n\nThe OAuth2 module for the yuncms.\n\n[![Latest Stable Version](https://poser.pugx.org/yuncms/yuncms-oauth2/v/stable.png)](https://packagist.org/packages/yuncms/yuncms-oauth2)\n[![Total Downloads](https://poser.pugx.org/yuncms/yuncms-oauth2/downloads.png)](https://packagist.org/packages/yuncms/yuncms-oauth2)\n[![Build Status](https://img.shields.io/travis/yuncms/yuncms-oauth2.svg)](http://travis-ci.org/yuncms/yuncms-oauth2)\n[![License](https://poser.pugx.org/yuncms/yuncms-oauth2/license.svg)](https://packagist.org/packages/yuncms/yuncms-oauth2)\n\n## Installation\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/). \n\nTo install, either run\n\n```\n$ php composer.phar require yuncms/yuncms-oauth2 \"~2.0.0\"\n```\nor add\n\n```\n\"yuncms/yuncms-oauth2\": \"~2.0.0\"\n```\n\nto the ```require``` section of your `composer.json` file.\n\nTo create database tables run migration command\n```\n$ yii migrate --migrationNamespace=@yuncms/oauth2/migrations\n```\n\n## Usage\n\nurl:\nApplication\n```bash\nhttp://yourname.com/oauth2/auth/authorize\n\nhttp://yourname.com/oauth2/auth/token\n\nrefresh_token\nhttp://yourname.com/oauth2/auth/token\n```\n\nOAuth 2.0 Authorization usage \n```php\nnamespace app\\controllers;\n\nuse app\\models\\LoginForm;\n\nclass AuthController extends \\yii\\web\\Controller\n{\n    public function behaviors()\n    {\n        return [\n            /** \n             * Checks oauth2 credentions and try to perform OAuth2 authorization on logged user.\n             * AuthorizeFilter uses session to store incoming oauth2 request, so \n             * you can do additional steps, such as third party oauth authorization (Facebook, Google ...)  \n             */\n            'oauth2Auth' =\u003e [\n                'class' =\u003e \\yuncms\\oauth2\\AuthorizeFilter::className(),\n                'only' =\u003e ['index'],\n            ],\n        ];\n    }\n    public function actions()\n    {\n        return [\n            /**\n             * Returns an access token.\n             */\n            'token' =\u003e [\n                'class' =\u003e \\yuncms\\oauth2\\TokenAction::classname(),\n            ],\n            /**\n             * OPTIONAL\n             * Third party oauth providers also can be used.\n             */\n            'back' =\u003e [\n                'class' =\u003e \\yii\\authclient\\AuthAction::className(),\n                'successCallback' =\u003e [$this, 'successCallback'],\n            ],\n        ];\n    }\n    /**\n     * Display login form, signup or something else.\n     * AuthClients such as Google also may be used\n     */\n    public function actionIndex()\n    {\n        $model = new LoginForm();\n        if ($model-\u003eload(\\Yii::$app-\u003erequest-\u003epost()) \u0026\u0026 $model-\u003elogin()) {\n            if ($this-\u003eisOauthRequest) {\n                $this-\u003efinishAuthorization();\n            } else {\n                return $this-\u003egoBack();\n            }\n        } else {\n            return $this-\u003erender('index', [\n                'model' =\u003e $model,\n            ]);\n        }\n    }\n    /**\n     * OPTIONAL\n     * Third party oauth callback sample\n     * @param OAuth2 $client\n     */\n    public function successCallback($client)\n    {\n        switch ($client::className()) {\n            case GoogleOAuth::className():\n                // Do login with automatic signup                \n                break;\n            ...\n            default:\n                break;\n        }\n        /**\n         * If user is logged on, redirects to oauth client with success,\n         * or redirects error with Access Denied\n         */\n        if ($this-\u003eisOauthRequest) {\n            $this-\u003efinishAuthorization();\n        }\n    }\n    \n}\n```\nApi controller sample\n```php\nclass ApiController extends \\yii\\rest\\Controller\n{\n    public function behaviors()\n    {\n        return [\n            /** \n             * Performs authorization by token\n             */\n            'tokenAuth' =\u003e [\n                'class' =\u003e \\yuncms\\oauth2\\TokenAuth::className(),\n            ],\n        ];\n    }\n    /**\n     * Returns username and email\n     */\n    public function actionIndex()\n    {\n        $user = \\Yii::$app-\u003euser-\u003eidentity;\n        return [\n            'username' =\u003e $user-\u003eusername,\n            'email' =\u003e  $user-\u003eemail,\n        ];\n    }\n}\n```\nSample client config\n```php\nreturn [\n...\n   'components' =\u003e [\n       'authClientCollection' =\u003e [\n            'class' =\u003e 'yii\\authclient\\Collection',\n            'clients' =\u003e [\n                'myserver' =\u003e [\n                    'class' =\u003e 'yii\\authclient\\OAuth2',\n                    'clientId' =\u003e 'unique client_id',\n                    'clientSecret' =\u003e 'client_secret',\n                    'tokenUrl' =\u003e 'http://myserver.local/auth/token',\n                    'authUrl' =\u003e 'http://myserver.local/auth/index',\n                    'apiBaseUrl' =\u003e 'http://myserver.local/api',\n                ],\n            ],\n        ],\n];\n```\n\n## Thanks to\n\n* [Yii framework](https://github.com/yiisoft/yii2)\n* [yii2-oauth2-server](https://github.com/borodulin/yii2-oauth2-server)\n\n## License\n\nYii2-oauth2 is released under the MIT License. See the bundled [LICENSE.md](LICENSE.md)\nfor details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrecmscom%2Fyuncms-oauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibrecmscom%2Fyuncms-oauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrecmscom%2Fyuncms-oauth2/lists"}