Почему не происходит авторизация пользователя после реквеста vk?
if ( isset($_GET['auth']) ) {
return $this->redirect(VK::getAuthUrl());
} else {
if ( isset($_GET['code']) && VK::getAccessToken($_GET['code']) ) {
// пользователь успешно авторизовался
return $this->redirect('/settings');
} else {
// ошибка
return $this->redirect('/?err');
}
}
получаем токен так
public static function getAccessToken($code = "") {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_URL => sprintf("https://oauth.vk.com/access_token?code=%s&client_id=%s&client_secret=%s&redirect_uri=%s",
$code,
self::$client_id,
self::$client_secret,
self::getHost())
));
$res = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ( $info['http_code'] == 200 ) {
$json = json_decode($res);
// info( $json);
return self::setAuth($json);
}
return false;
авторизация полученных данных ($json)
/**
* После успешной авторизации сохраняем данные о пользователе,
* его имя, срок сессии и т.д.
*
* Либо создаем нового пользователя.
*
* @param array $data - массив с токеном и инф. о пользователе после авторизации
*
* @return bool
*/
public static function setAuth(&$data) {
$user_id = Client::exist($data->user_id, 'vk');
if ( $user_id ) {
$client = new Client($user_id, false);
} else {
$client = new Client();
$client->email = $data->email;
$client->user_id = $data->user_id;
$client->social = 2;
$client->signed_up = gmdate('Y-m-d H:i:s');
$client->rfid = isset($_COOKIE['rfid']) ? (int)$_COOKIE['rfid'] : null;
$chat_room = new Chat();
$chat_room->put();
$client->id_chat = $chat_room->id;
// info($client);
}
$client->email = $client->email ? $client->email : $data->email;
$client->access_token = $data->access_token;
$client->expires_in = gmdate('Y-m-d H:i:s', time() + conf('General', 'session_duration'));
list($client->name, $client->pic) = self::getInfo($data->user_id);
if ( !$client->put() ) {
return false;
}
Client::releaseRfIdCookie();
// info($client);
return Client::auth($client, true);
}
}
Т.е я получаю массив данных от вк
stdClass Object
(
[access_token] => 3ad1809******************3b752a542b99**d435e
[expires_in] => 86399
[user_id] => 77777
)
сами заголовки в момент получения токена
(
[url] => https://oauth.vk.com/access_token?code=XXXX&client_id=XXXX&client_secret=XXXXXXXXXX&redirect_uri=https://XXXX/auth/vk
[content_type] => application/json; charset=utf-8
[http_code] => 200
[header_size] => 317
[request_size] => 191
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.1597
[namelookup_time] => 0.001203
[connect_time] => 0.042223
[pretransfer_time] => 0.089801
[size_upload] => 0
[size_download] => 143
[speed_download] => 899
[speed_upload] => 0
[download_content_length] => 143
[upload_content_length] => -1
[starttransfer_time] => 0.159643
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 87.240.129.135
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => xx.xxx.x.xxx
[local_port] => 47568
[http_version] => 3
[protocol] => 2
[ssl_verifyresult] => 0
[scheme] => HTTPS
[appconnect_time_us] => 89618
[connect_time_us] => 42223
[namelookup_time_us] => 1203
[pretransfer_time_us] => 89801
[redirect_time_us] => 0
[starttransfer_time_us] => 159643
[total_time_us] => 159700
)
в итоге контролер не редиректит на setting, и пользователь остается на /auth ( как будто просто произошла перезагрузка страницы, хотя данные есть ( куки, сессии)
в нжинксе 2378#82378: *6 connect() failed (111: Connection refused) while connecting to upstream, client: xx server:yyy, request: "GET /uu.css? HTTP/1.1", upstream: "https://127.0.0.1:443/build/app.min.js?", host: "$host", referrer: "https://$host/auth"
для ssl конфиг такой
server {
root $root_path;
set $root_path /var/www/xxx.ru;
set $php_sock unix:/var/run/php/php7.3-fpm.sock;
index index.php;
listen xx.x.xxx.xx:443 ssl;
server_name xxxx.ru;
proxy_read_timeout 200s;
access_log /var/log/nginx/xx/default-access.log;
error_log /var/log/nginx/xx/default-error.log;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /var/www/ssl/xx.crt;
ssl_certificate_key /var/www/ssl/xx.key;
location / {
root $root_path;
try_files $uri $uri/ /index.php?$args;
# proxy_pass https://127.0.0.1:443;
# proxy_redirect https://127.0.0.1:443/ /;
}
location @default_host {
# proxy_pass http://127.0.0.2:443;
# proxy_redirect http://127.0.0.2:443/ /;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass $php_sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}