Skip to content

Commit

Permalink
Fixed issue #4, return parameters for google is in json string instea…
Browse files Browse the repository at this point in the history
…d of normal http query string. Also fixed user query for Google based on latest doc in https://developers.google.com/accounts/docs/OAuth2Login

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jun 6, 2012
1 parent 136ecba commit aa32783
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
30 changes: 12 additions & 18 deletions libraries/oauth2/provider/google.php
Expand Up @@ -68,9 +68,8 @@ public function __construct(array $options = array())
$options['scope'] = array_merge(

// We need this default feed to get the authenticated users basic information
// array('https://www.googleapis.com/auth/plus.me'),
array('https://www.google.com/m8/feeds'),

array('https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'),

// And take either a string and array it, or empty array to merge into
(array) array_get($options, 'scope', array())
);
Expand All @@ -96,28 +95,23 @@ public function access($code, $options = array())

public function get_user_info(Token_Access $token)
{
$request = Request::make('resource', 'GET', 'https://www.google.com/m8/feeds/contacts/default/full', array(
$request = Request::make('resource', 'GET', 'https://www.googleapis.com/oauth2/v1/userinfo', array(
'access_token' => $token->access_token,
'max-results' => 1,
'alt' => 'json',
));

$response = json_decode($request->execute(), true);

// Fetch data parts
$email = array_get($response, 'feed.id.$t');
$name = array_get($response, 'feed.author.0.name.$t');
$name == '(unknown)' and $name = $email;
$user = json_decode($request->execute(), true);

return array(
'uid' => $email,
'nickname' => \Str::slug($name, '-'),
'name' => $name,
'email' => $email,
'uid' => $user['email'],
'nickname' => \Str::slug($user['name'], '-'),
'name' => $user['name'] . ' ' . $user['family_name'],
'email' => $user['email'],
'location' => null,
'image' => null,
'image' => $user['picture'],
'description' => null,
'urls' => array(),
'urls' => array(
'googleplus' => $user['link'],
),
);
}
}
7 changes: 6 additions & 1 deletion libraries/oauth2/request.php
Expand Up @@ -228,6 +228,11 @@ public function execute(array $options = null)
$url = "{$url}?{$query}";
}

return Core::remote($url, $options);
$response = Core::remote($url, $options);

// check if it's a json string
if ($this->name === 'access' and strpos(trim($response), '{') === 0) $response = http_build_query(json_decode($response, true));

return $response;
}
}

0 comments on commit aa32783

Please sign in to comment.