Делаю по инструкции
1) Настройка приложения
Код: Выделить всё
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\clients\Google',
'clientId' => '666463623678-er6-------------------',
'clientSecret' => 'GfznkQOLGo----------------------',
],
],
],
Код: Выделить всё
class IndexController extends Controller
{
....
public function actions()
{
return [
....
'social-auth' => [
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'onAuthSuccess'],
],
];
}
Код: Выделить всё
</div>
<div class="bottom-spacer"></div>
</section>
<?= yii\authclient\widgets\AuthChoice::widget([
'baseAuthUrl' => ['index/social-auth'],
'popupMode' => true,
]) ?>
https://prnt.sc/tbtlyn
то есть https://bublik.ru/index/social-auth?authclient=google
прописываю эту ссылку в гугле
https://prnt.sc/tbto7d
окно авторизации гугла открывается
https://prnt.sc/tbtoxz
значит URI Прописано правильно ибо при любых других вариантах ругается
5) выбираю акк через который нужно авториоваться
и вот получаю от гугла :
Request failed with code: 400, message: {
"error": "redirect_uri_mismatch",
"error_description": "Bad Request"
}
начинаю копать
и вот тут получается интересный момент
/vendor/yiisoft/yii2-authclient/src/OAuth2.php
Код: Выделить всё
public function fetchAccessToken($authCode, array $params = [])
{
if ($this->validateAuthState) {
$authState = $this->getState('authState');
$incomingRequest = Yii::$app->getRequest();
$incomingState = $incomingRequest->get('state', $incomingRequest->post('state'));
if (!isset($incomingState) || empty($authState) || strcmp($incomingState, $authState) !== 0) {
throw new HttpException(400, 'Invalid auth state parameter.');
}
$this->removeState('authState');
}
$defaultParams = [
'code' => $authCode,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->getReturnUrl(),
];
var_dump($defaultParams);
try {
$request = $this->createRequest()
->setMethod('POST')
->setUrl($this->tokenUrl)
->setData(array_merge($defaultParams, $params));
$this->applyClientCredentialsToRequest($request);
$response = $this->sendRequest($request);
}catch (\Exception $e){
print $e->getMessage();
}
var_dump($response);
exit;
в массиве $defaultParams
Код: Выделить всё
array(3) {
["code"]=>
string(89) "4/1gGklJwOOWLOrFBl4bZ0rfUfvVzjapA39TsvDVDaD84r1mdEZh4vEu2PYx4"
["grant_type"]=>
string(18) "authorization_code"
["redirect_uri"]=>
string(77) "https://bublik.ru/index/social-auth?authclient=google&authuser=0&prompt=none"
}
но в google то прописано https://bublik.ru/index/social-auth?authclient=google
попробовал добавить
получилось 2 URL
https://prnt.sc/tbtu8a
но эффект тот же
при этом
попробовал вот сюда насильно прописать https://bublik.ru/index/social-auth?authclient=google и все заработало !
Код: Выделить всё
$defaultParams = [
'code' => $authCode,
'grant_type' => 'authorization_code',
'redirect_uri' => 'https://bublik.ru/index/social-auth?authclient=google',
];
try {
$request = $this->createRequest()
->setMethod('POST')
->setUrl($this->tokenUrl)
->setData(array_merge($defaultParams, $params));
$this->applyClientCredentialsToRequest($request);
$response = $this->sendRequest($request);
}catch (\Exception $e){
print $e->getMessage();
}
var_dump($response);
exit;
как быть ?
вот тут оно этот URL берет
/vendor/yiisoft/yii2-authclient/src/BaseOAuth.php
Код: Выделить всё
/**
* @return string return URL.
*/
public function getReturnUrl()
{
if ($this->_returnUrl === null) {
$this->_returnUrl = $this->defaultReturnUrl();
}
return $this->_returnUrl;
}
/**
* Composes default [[returnUrl]] value.
* @return string return URL.
*/
protected function defaultReturnUrl()
{
return Yii::$app->getRequest()->getAbsoluteUrl();
}
помогите понять что не так веть в мануале все просто и элементарно
а умен тут целое расследование с ковыряниями