Skip to content

Instantly share code, notes, and snippets.

@davidhq
Last active December 18, 2015 23:28
Show Gist options
  • Save davidhq/5861453 to your computer and use it in GitHub Desktop.
Save davidhq/5861453 to your computer and use it in GitHub Desktop.
get user id from oauth token for elgg with elgg_social_login
<?php
function get_guid_from_oauth($provider, $token) {
global $CONFIG;
$identifier = strtolower($provider);
foreach (array("LinkedIn", "MySpace", "AOL") as $prov) {
$identifier = str_replace(strtolower($prov), $prov, $identifier);
}
$identifier = ucfirst($identifier) . "_" . $token;
$query = "SELECT entity_guid from {$CONFIG->dbprefix}private_settings where name = 'plugin:user_setting:elgg_social_login:uid' and value = '{$identifier}'";
$guid = get_data_row($query)->entity_guid;
if($guid) return $guid; else throw new Exception("User with OAuth identifier {$identifier} not found");
}
echo get_guid_from_oauth("facebook", "713936190");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment