im trying to create a social login using yiisoft/yii2-authclient
. And in my main.php i have this
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'clientId' => "xxxx",
'clientSecret' => "xxxx",
'attributeNames' => ['name', 'email', 'first_name', 'last_name'],
],
In my view i have this to create my social logins (override the extension view and put the file here yii2\frontend\views\user\security\login.php)
<?php $authAuthChoice = AuthChoice::begin([
'baseAuthUrl' => ['/user/security/auth']
]); ?>
<?php foreach ($authAuthChoice->getClients() as $client): ?>
<span class="btn btn-warning"><?= $authAuthChoice->clientLink($client) ?></span>
<?php endforeach; ?>
<?php AuthChoice::end(); ?>
the facebook button opens a popup, and the link is
`https://localhost/yii2/frontend/web/index.php?r=user%2Fsecurity%2Fauth&authclient=facebook`
but i get this error
`Argument 1 passed to Da\User\Controller\SecurityController::authenticate() must be an instance of Da\User\Contracts\AuthClientInterface, instance of yii\authclient\clients\Facebook given`
Not sure how to fix this, any ideas?? Thank you.
UPDATE:
Here is the actions()
and authenticate()
function in the SecurityController.php
public function actions()
{
return [
'auth' => [
'class' => AuthAction::class,
// if user is not logged in, will try to log him in, otherwise
// will try to connect social account to user.
'successCallback' => Yii::$app->user->isGuest
? [$this, 'authenticate']
: [$this, 'connect'],
],
];
}
public function authenticate(AuthClientInterface $client)
{
$this->make(SocialNetworkAuthenticateService::class, [$this, $this->action, $client])->run();
}