From d9bf93f11581930ae3ba35b43272ad26cef4b469 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 28 Feb 2016 12:35:26 -0800 Subject: [PATCH] Issue #1378 Steam support added. Fixes #1394 Broken social-login API links . --- .../hybridauth/Hybrid/Providers/Steam.php | 104 ++++++++++++++++++ e107_plugins/social/admin_config.php | 12 +- 2 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 e107_handlers/hybridauth/Hybrid/Providers/Steam.php diff --git a/e107_handlers/hybridauth/Hybrid/Providers/Steam.php b/e107_handlers/hybridauth/Hybrid/Providers/Steam.php new file mode 100644 index 000000000..373e8bf42 --- /dev/null +++ b/e107_handlers/hybridauth/Hybrid/Providers/Steam.php @@ -0,0 +1,104 @@ +user->profile->identifier = str_ireplace("http://steamcommunity.com/openid/id/", + "", $this->user->profile->identifier); + + if (!$this->user->profile->identifier) { + throw new Exception("Authentication failed! {$this->providerId} returned an invalid user ID.", 5); + } + + // If API key is not provided, use legacy API methods + if (!empty($this->config['keys']['key'])) { + $this->getUserProfileWebAPI($this->config['keys']['key']); + } else { + $this->getUserProfileLegacyAPI(); + } + + Hybrid_Auth::storage()->set("hauth_session.{$this->providerId}.user", $this->user); + } + + function getUserProfileWebAPI($apiKey) + { + $apiUrl = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + . $apiKey . '&steamids=' . $this->user->profile->identifier; + + $data = @file_get_contents($apiUrl); + $data = json_decode($data); + + if (!is_object($data) || !isset($data->response->players[0])) { + return false; + } + + // Get the first index in 'players' array + $data = $data->response->players[0]; + + $this->user->profile->displayName = property_exists($data, 'personaname') ? $data->personaname : ''; + $this->user->profile->firstName = property_exists($data, 'realname') ? $data->realname : ''; + $this->user->profile->photoURL = property_exists($data, 'avatarfull') ? $data->avatarfull : ''; + $this->user->profile->profileURL = property_exists($data, 'profileurl') ? $data->profileurl : ''; + $this->user->profile->country = property_exists($data, 'loccountrycode') ? $data->loccountrycode : ''; + } + + function getUserProfileLegacyAPI() + { + $apiUrl = 'http://steamcommunity.com/profiles/' . $this->user->profile->identifier . '/?xml=1'; + + $data = @file_get_contents($apiUrl); + $data = @ new SimpleXMLElement($data); + + if (!is_object($data)) { + return false; + } + + # store the user profile. + //$this->user->profile->identifier = ""; + if (property_exists($data, 'customURL') && (string) $data->customURL != '') { + $this->user->profile->profileURL = 'http://steamcommunity.com/id/' . (string) $data->customURL . '/'; + } + else { + $this->user->profile->profileURL = "http://steamcommunity.com/profiles/{$this->user->profile->identifier}/"; + } + + $this->user->profile->webSiteURL = ""; + $this->user->profile->photoURL = property_exists($data, 'avatarFull') ? (string)$data->avatarFull : ''; + $this->user->profile->displayName = property_exists($data, 'steamID') ? (string)$data->steamID : ''; + $this->user->profile->description = property_exists($data, 'summary') ? (string)$data->summary : ''; + $this->user->profile->firstName = property_exists($data, 'realname') ? (string)$data->realname : ''; + $this->user->profile->lastName = ""; + $this->user->profile->gender = ""; + $this->user->profile->language = ""; + $this->user->profile->age = ""; + $this->user->profile->birthDay = ""; + $this->user->profile->birthMonth = ""; + $this->user->profile->birthYear = ""; + $this->user->profile->email = ""; + $this->user->profile->emailVerified = ""; + $this->user->profile->phone = ""; + $this->user->profile->address = ""; + $this->user->profile->country = ""; + $this->user->profile->region = property_exists($data, 'location') ? (string)$data->location : ''; + $this->user->profile->city = ""; + $this->user->profile->zip = ""; + + } +} diff --git a/e107_plugins/social/admin_config.php b/e107_plugins/social/admin_config.php index f92e6ac08..742d5fd39 100644 --- a/e107_plugins/social/admin_config.php +++ b/e107_plugins/social/admin_config.php @@ -188,6 +188,10 @@ class social_ui extends e_admin_ui "keys" => array ( "key" => "", "secret" => "" ) ), */ + "Steam" => array ( + "enabled" => true, + "keys" => array ( "key" => "" ) + ), "Twitter" => array ( "enabled" => true, @@ -196,11 +200,6 @@ class social_ui extends e_admin_ui - - - - - ); @@ -212,6 +211,7 @@ class social_ui extends e_admin_ui "LinkedIn" => "https://www.linkedin.com/secure/developer", "Foursquare" => "https://www.foursquare.com/oauth/", "Github" => "https://github.com/settings/applications/new", + "Steam" => "http://steamcommunity.com/dev/apikey", ); @@ -313,7 +313,7 @@ class social_ui extends e_admin_ui foreach($this->social_logins as $prov=>$val) { - $label = varset($this->social_external[$prov]) ? "".$prov."" : $prov; + $label = varset($this->social_external[$prov]) ? "".$prov."" : $prov; $radio_label = strtolower($prov); $text .= "