'http://api.vk.com/oauth/authorize?client_id=' . $config['vk']['app_id'] .
'&response_type=code'.
'&scope=notify,friends'.
'&redirect_uri=' . urldecode( $config['vk']['redirect_url'])
public function http($url){
$ci = curl_init();
/* Curl settings */
curl_setopt($ci, CURLOPT_USERAGENT, 'dev-php');
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ci, CURLOPT_TIMEOUT, 20);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ci, CURLOPT_HEADER, false);
curl_setopt($ci, CURLOPT_URL, $url);
$response = curl_exec($ci);
curl_close($ci);
return $response;
}
/**
* Получить по коду access_token
* @param string $code секретный код от пользователя...
* @return array|false получаем данные в виде массива или false
**/
public function getAccessToken($code){
$response = json_decode($this->http('https://api.vk.com/oauth/access_token?client_id=' . $this->app_id .
'&client_secret=' . $this->app_key . '&code=' . $code . '&redirect_uri='. urldecode($this->app_redirect_url) ),true);
return $response;
}
app.get('/route', function(req, res) {
// ...
});
app.get('/route', [loadUser1, loadUser2, ..., loadUserN], function(req, res) {
// ...
});
function loadUser(req, res, next) {
if (req.session.user_id) {
next();
}
else {
res.redirect('/sessions/new');
}
}