Skip to content

Instantly share code, notes, and snippets.

@huglester
Created January 19, 2013 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huglester/4571606 to your computer and use it in GitHub Desktop.
Save huglester/4571606 to your computer and use it in GitHub Desktop.
Vkontakte support for ninjauath.
<?php
// source; https://github.com/Maxlab/fuelphp/blob/master/fuel/packages/oauth2/classes/provider/vkontakte.php
// bugs? https://github.com/happyninjas/fuel-ninjauth/issues/37
/**
* Vkontakte OAuth2 Provider
*
* @package FuelPHP/OAuth2
* @category Provider
* @author Max Znamensky
*/
namespace OAuth2;
class Provider_Vkontakte extends Provider
{
public $uid_key = 'user_id';
public function url_authorize()
{
return 'http://oauth.vk.com/authorize';
}
public function url_access_token()
{
return 'https://oauth.vk.com/access_token';
}
public function get_user_info(Token_Access $token)
{
$scope = array('nickname', 'screen_name','photo_big');
$url = 'https://api.vk.com/method/users.get?'.http_build_query(array(
'uids' => $token->uid,
'fields' => implode(",",$scope),
'access_token' => $token->access_token,
));
$user = json_decode(file_get_contents($url))->response;
if(sizeof($user)==0)
return null;
else
$user = $user[0];
/*if ( isset($user))
{
throw new Exception(array('message' => 'Required option not passed: access_token'.PHP_EOL.print_r($user, true)));
}*/
return array(
'uid' => $user->uid,
'nickname' => isset($user->nickname) ? $user->nickname : null,
'name' => isset($user->first_name) ? $user->first_name : null,
'email' => null,
'image' => isset($user->photo_big) ? $user->photo_big : null,
'urls' => array(),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment