| 10582 |
lgm |
1 |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
2 |
/**
|
|
|
3 |
* Vkontakte OAuth2 Provider
|
|
|
4 |
*
|
|
|
5 |
* @package CodeIgniter/OAuth2
|
|
|
6 |
* @category Provider
|
|
|
7 |
* @author Lavr Lyndin
|
|
|
8 |
*/
|
|
|
9 |
|
|
|
10 |
class OAuth2_Provider_Vkontakte extends OAuth2_Provider
|
|
|
11 |
{
|
|
|
12 |
protected $method = 'POST';
|
|
|
13 |
public $uid_key = 'user_id';
|
|
|
14 |
|
|
|
15 |
public function url_authorize()
|
|
|
16 |
{
|
|
|
17 |
return 'http://oauth.vk.com/authorize';
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public function url_access_token()
|
|
|
21 |
{
|
|
|
22 |
return 'https://oauth.vk.com/access_token';
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
public function get_user_info(OAuth2_Token_Access $token)
|
|
|
26 |
{
|
|
|
27 |
$scope = array('nickname', 'screen_name','photo_big');
|
|
|
28 |
$url = 'https://api.vk.com/method/users.get?'.http_build_query(array(
|
|
|
29 |
'uids' => $token->uid,
|
|
|
30 |
'fields' => implode(",",$scope),
|
|
|
31 |
'access_token' => $token->access_token,
|
|
|
32 |
));
|
|
|
33 |
|
|
|
34 |
$user = json_decode(file_get_contents($url))->response;
|
|
|
35 |
|
|
|
36 |
if(sizeof($user)==0)
|
|
|
37 |
return null;
|
|
|
38 |
else
|
|
|
39 |
$user = $user[0];
|
|
|
40 |
|
|
|
41 |
return array(
|
|
|
42 |
'uid' => $user->uid,
|
|
|
43 |
'nickname' => isset($user->nickname) ? $user->nickname : null,
|
|
|
44 |
'name' => isset($user->name) ? $user->name : null,
|
|
|
45 |
'first_name' => isset($user->first_name) ? $user->first_name : null,
|
|
|
46 |
'last_name' => isset($user->last_name) ? $user->last_name : null,
|
|
|
47 |
'email' => null,
|
|
|
48 |
'location' => null,
|
|
|
49 |
'description' => null,
|
|
|
50 |
'image' => isset($user->photo_big) ? $user->photo_big : null,
|
|
|
51 |
'urls' => array(),
|
|
|
52 |
);
|
|
|
53 |
}
|
|
|
54 |
}
|