This extension adds OpenID, OAuth, and OAuth2 consumers for the Yii 2.0 framework.
composer require yiisoft/yii2-authclient
authClientCollection
component:'components' => [ // ... 'authClientCollection' => [ 'class' => 'yiiauthclientCollection', 'clients' => [ 'google' => [ 'class' =>'yiiauthclientclientsGoogleOpenId' ], 'github' => [ 'class' => 'yiiauthclientclientsGitHub', 'clientId' => '87f0784aae2ac48f78a', 'clientSecret' =>'fb5953a54dea4640f3a70d8abd96fbd25592ff18', ], // etc. ], ], ],
SiteController
and add the auth
standalone action and success callback method:use yiiauthclientClientInterface; public function actions() { return [ // ... 'auth' => [ 'class' => 'yiiauthclientAuthAction', 'successCallback' => [$this, 'onAuthSuccess'], ], ]; } public function onAuthSuccess(ClientInterface $client) { $attributes = $client->getUserAttributes(); yiihelpersVarDumper::dump($attributes, 10, true); exit; }
views/site/login.php
file and insert the AuthChoice
widget:<div class="site-login"> <h1><?= Html::encode($this->title) ?></h1> <div class="panel panel-default"> <div class="panel-body"> <?= yiiauthclientwidgetsAuthChoice::widget(['baseAuthUrl' => ['site/auth'], 'popupMode' => false, ]) ?> </div> </div> <p>Please fill out the following fields to login:</p> ... </div>
[ 'login' => 'Name' 'id' => 0000000 'avatar_url' =>'https://avatars.githubusercontent.com/u/0000000?v=3' 'gravatar_id' => '' 'url' => 'https://api.github.com/users/Name' 'html_url' => 'https://github.com/Name' ... 'name' => 'YourName' 'blog' =>site.com' 'email => [email protected]' ... ]
onAuthSuccess
method, like the example at https://github.com/yiisoft/yii2-authclient/blob/master/docs/guide/quick-start.md.The extension provides OpenID, OAuth, and OAuth2 auth clients for your application.
The AuthChoice
widget opens an authenticate page on a selected service's site, storing the auth
action URL. After authentication, the current service redirects users back while sending authentication data via a POST-request. AuthAction
receives the request and calls the corresponding callback.
3.17.128.129